我正在编写一个Web服务,假设将json两个json字符串保存到DB。 我可以使用sope UI和WCF Test Client调用它,但我无法通过浏览器调用它。 有办法做到这一点吗?
该服务最初将由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 :(得分:8)
web.config中有几个错误:
没有名为ServiceBehaviour behaviorConfiguration="ServiceBehaviour"
的服务行为
没有名为web的端点行为:behaviorConfiguration="web"
没有给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>