【发布时间】:2015-01-20 11:00:56
【问题描述】:
我是 Web 服务的新手,我正在尝试配置我的 WCF 服务以使用 Visual WCF 服务模板从另一个服务中提取文件。
我已经设法提取了除内容数据之外的所有内容。我搜索并发现我必须使用 Mtom 而不是 Text 进行消息编码。问题是我不确定如何配置我的 Web 服务以使用 MessageEncoding = Mtom。我已经修改了 web.config 文件,但似乎无法正确配置它。
这是我的服务接口
[ServiceContract]
public interface IService
{
[OperationContract]
string test(changeData data);
[OperationContract]
RetrieveChangeListResponse GetChangeList();
[OperationContract]
RetrieveChangeTaskListResponse GetTaskList();
[OperationContract]
RetrieveInteractionAttachmentResponse GetFile(string id);
// TODO: Add your service operations here
}
这是我的 web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000"
messageEncoding ="Mtom">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="IService"
behaviorConfiguration="ServiceWithMetadata">
<endpoint name="BasicHttpBinding_IService"
binding="basicHttpBinding"
bindingConfiguration="basicHttp"
contract="IService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceWithMetadata">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
目前如果使用此设置,我会收到此错误:
错误:无法从 localhost:50282/Service.svc 获取元数据 如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于 URI 的 MSDN 文档:localhost:50282/Service.svc 元数据包含无法解析的引用:'localhost:50282/Service.svc'。内容类型应用程序/soap+xml;服务 localhost:50282/Service.svc 不支持 charset=utf-8。客户端和服务绑定可能不匹配。远程服务器返回错误:(415)无法处理消息,因为内容类型'application/soap+xml; charset=utf-8' 不是预期的类型 'text/xml; charset=utf-8'..HTTP GET 错误 URI: localhost:50282/Service.svc HTML 文档不包含 Web 服务发现信息。
如果我删除这些设置,我会得到这样的类型不匹配:
客户端发现响应内容类型为'multipart/related;类型=“文本/xml”;边界="----=_Part_0_30957184.1421681490926"',但应为'text/xml'。
我知道有一个 WcfTestClient 配置和一个实际服务配置,但我不明白如何正确配置我的服务器端以正确接受 Mtom 编码。
有人可以解释如何正确配置服务器端绑定吗?我使用 BasicHttpBinding,但也想将 wshHttpBinding 用于soap 1.2 功能。
提前致谢。
【问题讨论】:
标签: c# .net web-services wcf soap