2013-04-07 91 views
3

即时通讯编写一个web服务,假设将json两个json字符串保存到数据库。 我可以调用它与UI和WCF测试客户端,但我不能从我的浏览器调用它。 有没有办法做到这一点?如何从浏览器调用我的WCF服务?

该服务最初将被android应用程序使用,并且我已经尝试过从它调用没有任何运气。

谢谢先进。

这里是我的服务

[ServiceContract] 
public interface IRService 
{ 
    [OperationContract] 
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, 
     BodyStyle = WebMessageBodyStyle.Wrapped, 
     UriTemplate = "SaveCallResults?callInfo={callInfo}&testInfo={testInfo}")] 
    string SaveCallResults(string callInfo, string testInfo); 
} 

的界面,这里是我的web.config

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_RService" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false"   hostNameComparisonMode="StrongWildcard" 
     maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536" 
     textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" 
     messageEncoding="Text"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
     maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name=""> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" 
    multipleSiteBindingsEnabled="true" /> 
<services> 
    <!-- causing error --> 
    <!--<service name="NovaRoadRunnerWS.RService" behaviorConfiguration="ServiceBehaviour" > 
    <endpoint address="" binding="webHttpBinding" contract="NovaRoadRunnerWS.IRService" behaviorConfiguration="web" > 
    </endpoint> 
    </service>--> 
</services> 

+0

您正在服务上使用'webHttpBinding',但是您正在为**'basicHttpBinding'创建自定义绑定配置** - 为什么?!?!? – 2013-04-07 18:28:11

回答

8

有几个错误在web.config:

  1. 有命名ServiceBehaviour没有服务行为behaviorConfiguration="ServiceBehaviour"

  2. 没有终点的行为称为网络:behaviorConfiguration="web"

  3. 没有名字给了serviceBehaviors部分:<behavior name="">

我做了如下改变来解决错误:

<behaviors> 
    <serviceBehaviors> 
    <behavior name="web"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

and

<services> 
    <service name="NovaRoadRunnerWS.RService" behaviorConfiguration="web" > 
    <endpoint address="" binding="webHttpBinding" contract="NovaRoadRunnerWS.IRService" > 
    </endpoint> 
    </service> 
</services> 
+0

是的 - 这个''是新的.NET 4.0 **默认 - 如果你没有为一个行为指定一个名字,那么这些是**默认设置**。这是一个功能 - 不是bug! – 2013-04-07 18:26:25