WSDL で SoapAction が 空文字 の Webサービス を .NET で実装してみる

備忘録に。。以下のような WSDL があります。

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types />
  <wsdl:message name="HelloWorldSoapIn" />
  <wsdl:message name="HelloWorldSoapOut">
    <wsdl:part name="HelloWorldResult" type="s:string" />
  </wsdl:message>
  <wsdl:message name="HelloWorld2SoapIn">
    <wsdl:part name="param" type="s:string" />
  </wsdl:message>
  <wsdl:message name="HelloWorld2SoapOut">
    <wsdl:part name="HelloWorld2Result" type="s:string" />
  </wsdl:message>
  <wsdl:portType name="Service1Soap">
    <wsdl:operation name="HelloWorld">
      <wsdl:input message="tns:HelloWorldSoapIn" />
      <wsdl:output message="tns:HelloWorldSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="HelloWorld2">
      <wsdl:input message="tns:HelloWorld2SoapIn" />
      <wsdl:output message="tns:HelloWorld2SoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="Service1Soap" type="tns:Service1Soap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
    <wsdl:operation name="HelloWorld">
      <soap:operation soapAction="" style="rpc" />
      <wsdl:input>
        <soap:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="HelloWorld2">
      <soap:operation soapAction="" style="rpc" />
      <wsdl:input>
        <soap:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="Service1Soap12" type="tns:Service1Soap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
    <wsdl:operation name="HelloWorld">
      <soap12:operation soapAction="" style="rpc" />
      <wsdl:input>
        <soap12:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://www.w3.org/2003/05/soap-encoding" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://www.w3.org/2003/05/soap-encoding" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="HelloWorld2">
      <soap12:operation soapAction="" style="rpc" />
      <wsdl:input>
        <soap12:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://www.w3.org/2003/05/soap-encoding" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://www.w3.org/2003/05/soap-encoding" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Service1">
    <wsdl:port name="Service1Soap" binding="tns:Service1Soap">
      <soap:address location="http://localhost:1711/WebService1.asmx" />
    </wsdl:port>
    <wsdl:port name="Service1Soap12" binding="tns:Service1Soap12">
      <soap12:address location="http://localhost:1711/WebService1.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

こいつは、RPC を使っていて SoapAction が 空文字("") です。
まず、サーバー側のインターフェースを生成します。
wsdl.exe MSDN Web サービス記述言語ツール (Wsdl.exe) を /serverInterface オプション(/si:)を指定して実行します。

生成されたコードはこちら。

//------------------------------------------------------------------------------
// <auto-generated>
//     このコードはツールによって生成されました。
//     ランタイム バージョン:4.0.21006.1
//
//     このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
//     コードが再生成されるときに損失したりします。
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

// 
// このソース コードは wsdl によって自動生成されました。Version=4.0.21006.1 です。
// 


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.21006.1")]
[System.Web.Services.WebServiceBindingAttribute(Name = "Service1Soap", Namespace = "http://tempuri.org/")]
public interface IService1Soap
{

  /// <remarks/>
  [System.Web.Services.WebMethodAttribute()]
  [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
  string HelloWorld();

  /// <remarks/>
  [System.Web.Services.WebMethodAttribute()]
  [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
  string HelloWorld2(string param);
}

このインターフェースを Webサービスクラス(.asmx)に実装します。

using System.Web.Services;
using System.Web.Services.Protocols;

namespace WebService1
{
  /// <summary>
  /// WebService1 の概要の説明です
  /// </summary>
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.None)] // これ重要!
  [SoapRpcService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)] // これ重要!
  public class WebService1 : WebService, IService1Soap
  {
    string IService1Soap.HelloWorld()
    {
      return "Hello WebService1";
    }

    string IService1Soap.HelloWorld2(string param)
    {
      return "Hello2 WebService1" + param;
    }
  }
}

ここで注意点が二つあります。
まず、WebServiceBinding 属性ですが、通常(Webサービスクラス新規作成時) は、下記の様になっています。

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

しかし、RPC を使用しているので、BasicProfile 準拠ではないため、WsiProfiles.None を指定します。
MSDN WsiProfiles 列挙体


次に、SoapAction が空文字なので、System.Web.Services.Protocols.SoapRpcService 属性 の RoutingStyle プロパティ に SoapServiceRoutingStyle.RequestElement を指定します。
MSDN SoapServiceRoutingStyle 列挙体


rpc/encoded や document/literal、SoapAction 等詳しく知らない単語が沢山出てきて困った。
IDE や フレームワークを使ってると、こういう基礎的な事を知らなくても動く物が出来るってのは、利点でもあり欠点でもあるのかな?
いや、まあ単に勉強不足なだけなのかも…。