5

我正在编写一个网络服务,假设将 json 两个 json 字符串保存到 DB。我可以使用 sope UI 和 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>

4

1 回答 1

9

web.config中有几个错误:

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

  2. 没有名为 web 的端点行为:behaviorConfiguration="web"

  3. serviceBehaviors 部分没有命名: <behavior name="">

我进行了以下更改以修复错误:

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

<services>
  <service name="NovaRoadRunnerWS.RService" behaviorConfiguration="web" >
    <endpoint address="" binding="webHttpBinding" contract="NovaRoadRunnerWS.IRService"  >
    </endpoint>
  </service>
</services>
于 2013-04-07T17:13:10.500 回答