简体   繁体   English

配置WCF服务服务器端以接受Mtom

[英]Configure WCF service server side to accept Mtom

I'm pretty new to web services and I'm trying to configure my WCF service to pull files from another service using the Visual WCF service template. 我是Web服务的新手,我正在尝试配置WCF服务以使用Visual WCF服务模板从另一个服务中提取文件。

I've managed to pull everything except for the content data. 我设法拉除内容数据之外的所有内容。 I've searched and found that I have to use Mtom instead of Text for message encoding. 我搜索后发现,必须使用Mtom而不是Text进行消息编码。 Problem is i'm not sure how to configure my web service to use MessageEncoding = Mtom. 问题是我不确定如何配置我的Web服务以使用MessageEncoding = Mtom。 I've fiddled with the web.config file but i can't seem to configure it properly. 我摆弄了web.config文件,但似乎无法正确配置它。

This is my service interface 这是我的服务界面

 [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
}

This is my web.config 这是我的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"/>

Currently if use this setup I get this error: 当前,如果使用此设置,则会出现此错误:

Error: Cannot obtain Metadata from localhost:50282/Service.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. 错误:无法从localhost:50282 / Service.svc获取元数据。如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。 For help enabling metadata publishing, please refer to the MSDN documentation at URI: localhost:50282/Service.svc Metadata contains a reference that cannot be resolved: 'localhost:50282/Service.svc'. 有关启用元数据发布的帮助,请参阅URI上的MSDN文档:localhost:50282 / Service.svc元数据包含无法解析的引用:“ localhost:50282 / Service.svc”。 Content Type application/soap+xml; 内容类型application / soap + xml; charset=utf-8 was not supported by service localhost:50282/Service.svc. 服务localhost:50282 / Service.svc不支持charset = utf-8。 The client and service bindings may be mismatched. 客户端和服务绑定可能不匹配。 The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; 远程服务器返回错误:(415)由于内容类型为'application / soap + xml,因此无法处理该消息; charset=utf-8' was not the expected type 'text/xml; charset = utf-8'不是预期的类型'text / xml; charset=utf-8'..HTTP GET Error URI: localhost:50282/Service.svc The HTML document does not contain Web service discovery information. charset =utf-8'。HTTPGET错误URI:localhost:50282 / Service.svc HTML文档不包含Web服务发现信息。

If I remove these settings I get a type mismatch like this: 如果删除这些设置,则会得到如下类型的不匹配:

Client found response content type of 'multipart/related; 客户发现响应内容类型为“多部分/相关”; type="text/xml"; 类型= “文本/ xml” 的; boundary="----=_Part_0_30957184.1421681490926"', but expected 'text/xml'. boundary =“ ---- = _ Part_0_30957184.1421681490926””,但应为'text / xml'。

I understand there is a config for the WcfTestClient and a config for the actual service, but I don't understand how to properly configure my server side to properly accept Mtom encoding. 我知道有一个针对WcfTestClient的配置和一个针对实际服务的配置,但是我不了解如何正确配置服务器端以正确接受Mtom编码。

Could someone explain how to properly configure the server side binding ? 有人可以解释如何正确配置服务器端绑定吗? I use BasicHttpBinding , but would also like to use wshHttpBinding for soap 1.2 functionality. 我使用BasicHttpBinding ,但也想将wshHttpBinding用于soap 1.2功能。

Thanks in advance. 提前致谢。

The problem was in the the authentification method used, i was using annonymous instead of basic. 问题出在所使用的身份验证方法中,我使用的是匿名名称而不是基本名称。 Also you can't have method return types that are proxy data types. 同样,您不能拥有作为代理数据类型的方法返回类型。 If you have such a method you will get an error about class derivation. 如果您有这样的方法,您将得到有关类派生的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM