【发布时间】:2014-04-23 03:38:50
【问题描述】:
我已经开发了一个 WCF REST 服务并尝试使用 Asp.net 进行测试,尽管它可以与 wcf 测试客户端一起使用。该服务可能被非点网客户端使用。
我正在尝试在 asp.net 中创建一个测试页面,以通过 post 验证此服务。目前,此服务托管在我的 IIS 中
服役中:
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/MySVC?stringP={stringP}")]
Stream MySVC(string stringP);
在 asp.net 中
$.ajax({
type: "POST", //GET or POST or PUT or DELETE verb
url: "http://localhost/MySvcHost/MySVC.svc?stringP",
cache: false,
data: '[{stringP:"samplestring"}]',
dataType: "jsonp",
processData: true,
success: function (msg) {
},
error: function (err) {
}
})
当我运行测试应用程序时,它进入错误块 & Fiddler 显示错误“方法不允许”并显示为 GET。我还看到了附加参数(callback=)如果我将“jsonp”更改为“json”,它会抛出“传输错误”
我该怎么办?
更新: 服务 web.config
<system.serviceModel>
<services>
<service
name="Service.ParseService" behaviorConfiguration="ServiceBehaviour" >
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web"
contract="Service.RestServiceInterface" name="BasicHttpBinding_RestServiceInterface2">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000" useDefaultWebProxy="true" allowCookies="false" name="crossDomain" crossDomainScriptAccessEnabled="true" hostNameComparisonMode="StrongWildcard" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"
maxBufferSize="2147483647" transferMode="Buffered"
bypassProxyOnLocal="false">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="1024" maxStringContentLength="2147483647" maxNameTableCharCount="16384"></readerQuotas>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
客户端 web.config
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webEndpoint">
<webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json"
helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="BasicHttpBinding_RestServiceInterface2" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="1024" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint behaviorConfiguration="webEndpoint" address="http://localhost:14502/MySvcHost/MySVC.svc" binding="webHttpBinding" bindingConfiguration="BasicHttpBinding_RestServiceInterface2" contract="MySVC.RestServiceInterface" name="BasicHttpBinding_RestServiceInterface2"/>
</client>
【问题讨论】:
-
我怀疑是 Stream 返回类型,你能用字符串等其他返回类型来测试它吗?
-
我怀疑,它与 Stream 类型无关。我更改为字符串并在应用程序中遇到相同的错误。事实上,我尝试通过托管链接访问..