0

背景情報: C# で Web サービスを使用するクライアントを構築します。svcutil を使用してプロキシ クラスを自動生成しました。Web サービスは、MTOM 経由で PDF 添付ファイルを送信するように設定されています。プロキシからの API 呼び出しを使用してそうしようとすると、次のエラーが発生します。

Client found response content type of 'multipart/related; boundary="MIMEBoundaryurn_uuid_5D7E9AC12266BFFBDB1370543444063"; start-info="text/xml"; type="text/xml"; start="<0.urn:uuid:5D7E9AC12266BFFBDB1370543444064@apache.org>"', but expected 'text/xml'.

...これは、クライアントが MTOM 用に適切に構成されていないことを意味します。わかりました、クールです。構成を変更してそうする方法の例がいくつかあります。ただし、ここでつまずきます-これまでに見つけたすべての例では、構成ファイルが私の設定とは異なる方法でマッピングされています。例では、セクションに 2 つの項目が設定されてsystem.serviceModelいます。1 つはバインディング用、もう 1 つはエンドポイント アドレスを含むクライアント エンドポイント用です。私の自動生成された構成は、アドレスを にドロップしますがapplicationSettings、まあ、私は混乱しています。:( ここにそれらが並んでいます:

例:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IUpload" messageEncoding="Mtom"/>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/ServiceModelSamples/service.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IUpload" contract="IUpload">
      </endpoint>
    </client>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

私の:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=----------------" >
          <section name="TWS.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=----------------" requirePermission="false" />
        </sectionGroup>
      </configSections>
      <applicationSettings>
        <TWS.Properties.Settings>
          <setting name="TWS_WebService_WsApiService" serializeAs="String">
            <value>https://www.<redacted>.com/services/WsApiService/</value>
          </setting>
        </TWS.Properties.Settings>
      </applicationSettings>
    </configuration>

プロキシ クラスで API 呼び出し自体を設定する方法は次のとおりです。

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost:8080/getStiDoc", RequestNamespace="http://www.<redacted>.com/ws/schemas", ResponseNamespace="http://www.<redacted>.com/ws/schemas", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("doc", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="base64Binary", IsNullable=true)]
        public byte[] getDoc([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)] string username, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="integer", IsNullable=true)] string id) {
            object[] results = this.Invoke("getDoc", new object[] {
                        username,
                        id});
            return ((byte[])(results[0]));
        }

私の質問は次のとおりです。構成ファイルの設定方法で、適切なバインディングを追加して、base64 バイナリではなく MTOM を確実に検索するようにするにはどうすればよいですか?

4

1 に答える 1