我的子域中没有HTTPS(SSL),因此像HTTPS一样,任何东西都掉了,只有HTTP。
我的WCF服务中有一个操作,由于返回类型很复杂,至少根据错误消息,它需要SOAP。
[OperationContract(IsOneWay = false)]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
FileDownloadReturnMessage DownloadFile(FileDownloadMessage request);
我必须将绑定安全性更改为None
,因为Transport
至少从收到的错误消息中需要HTTPS; WsHttpBinding
也是一样,因此现在basicHttpBinding
。目前,web.config具有3个绑定:webHttpBinding
,basicHttpBinding
和mex
。
问题是SOAP和HTTP似乎不兼容。将URL粘贴到Google Chrome浏览器中时,出现以下错误消息:
[InvalidOperationException:合同'ICloudService'中的操作'DownloadFile'使用具有SOAP标头的MessageContract。无MessageVersion不支持SOAP标头。]
这是URI:
http://mycloud.thedomain.com/Communication/CloudService.svc/AddressWs
以下URI引发相同的错误。
http://mycloud.thedomain.com/Communication/CloudService.svc/AddressWeb
这里是web.config
:
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.6.2"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.serviceModel>
<services>
<service name="MyCloud.Communication.CloudService" behaviorConfiguration="BehaviorMyCloudService">
<endpoint address="/AddressWeb"
binding="webHttpBinding"
bindingConfiguration="EndpointBindingMyCloudService"
contract="MyCloud.Communication.ICloudService"
behaviorConfiguration="endpointBehaviorWeb"
>
</endpoint>
<endpoint address="/AddressWs"
binding="basicHttpBinding"
bindingConfiguration="EndpointBindingMyCloudService"
contract="MyCloud.Communication.ICloudService"
behaviorConfiguration="endpointBehaviorWs"
>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BehaviorMyCloudService">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="80" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="endpointBehaviorWeb">
<webHttp defaultOutgoingResponseFormat="Xml" />
</behavior>
<behavior name="endpointBehaviorWs">
<webHttp defaultOutgoingResponseFormat="Xml" />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" bindingConfiguration="EndpointBindingMyCloudService" />
<add scheme="https" binding="webHttpBinding" bindingConfiguration="EndpointBindingMyCloudService" />
</protocolMapping>
<bindings>
<webHttpBinding>
<binding
name="EndpointBindingMyCloudService"
allowCookies="false"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647"
useDefaultWebProxy="true"
>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding
name="EndpointBindingMyCloudService"
allowCookies="false"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647"
useDefaultWebProxy="true"
>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://localhost:80"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
</configuration>
我的C#代码引发了一个烦人的错误:
ex = {“无法激活请求的服务'http://mycloud.thedomain.com/Communication/CloudService.svc/AddressWs'。有关更多信息,请参阅服务器的诊断跟踪日志。”}
将URL保留在Chrome浏览器中会更好。
我需要对web.config
进行哪些更改以获取复杂的返回值并仍使用HTTP?