を、以下の方法はあなたのためにそれを行います。
有効なリクエストメッセージとエンドポイントとsoapactionを受け取り、サービスによって返された未処理のxmlを返します。
Message何か他のものを与えたい場合は、ServiceContract属性とOperationContract属性で修飾されたIRequestChannelの代わりを実装する必要があります。
あなたが設定ファイルから2つのパラメータをフェッチする、または何らかの定数値を使用することができます上記の方法を使用するには
// give it a valid request message, endpoint and soapaction
static string CallService(string xml, string endpoint, string soapaction)
{
string result = String.Empty;
var binding = new BasicHttpBinding();
// create a factory for a given binding and endpoint
using (var client = new ChannelFactory<IRequestChannel>(binding, endpoint))
{
var anyChannel = client.CreateChannel(); // Implements IRequestChannel
// create a soap message
var req = Message.CreateMessage(
MessageVersion.Soap11,
soapaction,
XDocument.Parse(xml).CreateReader());
// invoke the service
var response = anyChannel.Request(req);
// assume we're OK
if (!response.IsFault)
{
// get the body content of the reply
var content = response.GetReaderAtBodyContents();
// convert to string
var xdoc = XDocument.Load(content.ReadSubtree());
result = xdoc.ToString();
}
else
{
//throw or handle
throw new Exception("panic");
}
}
return result;
}
:あなたが越えてあなたの設定ファイル内の他の構成を必要としません
var result = CallService(
@"<GetData xmlns=""http://tempuri.org/""><value>42</value></GetData>",
ConfigurationManager.AppSettings["serviceLink"],
ConfigurationManager.AppSettings["serviceSoapAction"]);
// example without using appSettings
var result2 = CallService(
@"<GetValues xmlns=""http://tempuri.org/""></GetValues>",
"http://localhost:58642/service.svc",
"http://tempuri.org/IService/GetValues");
お知らせ:
<appSettings>
<add key="serviceLink" value="http://localhost:58642/service.svc"/>
<add key="serviceSoapAction" value="http://tempuri.org/IService/GetData"/>
</appSettings>
は、SOAPアクションを把握するために、サービスのWSDLを使用します。
<wsdl:binding name="BasicHttpBinding_IService" type="tns:IService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetData">
<soap:operation soapAction="http://tempuri.org/IService/GetData" style="document"/>
とそのportTypeのとメッセージを通じてそのルートに従うことによって、あなたがタイプ見つける:あなたはGetDataのためのXMLペイロードの形状を構築することができ
<wsdl:types>
<xs:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.datacontract.org/2004/07/"/>
<xs:element name="GetData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="value" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
、そこからの:
<GetData xmlns="http://tempuri.org/">
<value>42</value>
</GetData>
ですかこれらのエンドポイントごとにインターフェースを用意しています(これらを設定したり、それらを識別する方法もあります)。または、応答の本文が文字列として返されると常に期待していますか? – rene
xmlファイルを返します。 xmlファイルが到着したら、次のプロセスを動的に設定します。私はその時点で何の問題もありません。残念ながら、これらのエンドポイントのためのインタフェースはありません。私は実際の問題はとにかくここにいると思います。 @rene –