(私のニーズは単純で完全なMono互換性が必要なので、私はWCFではなく.Net 2.0 Webサービスを使用しています...)XML SOAPメッセージ内に "Raw XML"を送信する方法。 C#、.Net Webサービス
私はC# Visual Studioの初心者、私は基本的な質問をお詫び申し上げます。
私が通信しているSOAPサービスはWSDLを提供しており、.NET Webサービスの参照を作成するために使用しました。ここまでは順調ですね。そう(例...)
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Search xmlns="http://foo.bar/bazservice/">
<session>ABCDEF</session>
<options>
<![CDATA[<Search>
<SearchConditions>
<Condition>
<Field>1234</Field>
<Value>Test Record</Value>
</Condition>
</SearchConditions>
<Fields>
<Field>5678</Field>
</Fields>
</Search>]]>
</options>
</Search>
</soap:Body>
</soap:Envelope>
だから私は、Visual Studioは魔法に十分素敵だったと生成されたコードを使用して、私の関数を呼び出すように
はしかし、サービスは、ペイロードがXML文字列であることを期待します私にとっては、このような:
// Build an XML thing, and encapsulate it in a CDATA
XElement searchQuery = this.BuildSearchXml(params, search);
XCData cdata = new XCData(searchQuery.ToString());
// XML String looks good...
Console.WriteLine(cdata.ToString() + Environment.NewLine);
// Let's send XML payload to service...
search client = this.Connect("search");
// Search() expects the second argument to be an XML string...
var returnVal = client.Search(session, cdata.ToString(), 1);
return returnVal.ToString();
残念ながら、Webサービスのグルーコードは、どこかで生成された魔法で、自動的にXML文字列をurlencodes!
いくつかのtcpdump調査を行う場合、ここではそれが実際に送信されますと、ペイロードがあります:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Search xmlns="http://foo.bar/bazservice/">
<session>ABCDEF</session>
<options>
<![CDATA[<Search>
<SearchConditions>
<Condition>
<Field>1234</Field>
<Value>Test Record</Value>
</Condition>
</SearchConditions>
<Fields>
<Field>5678</Field>
</Fields>
</Search>]]>
</options>
</Search>
</soap:Body>
</soap:Envelope>
私の質問はこれです:どのように私はそれがWSDLで生成されたとして、Web参照の魔法を使用し続けるが、それを教えてください〜なし URLEncode生のXML文字列ですが、そのまま送信しますか?
私は非常に初心者です - 私は生成されたコード(in \ Web References \ MyService \ Reference.cs)を見ていますが、私は迷っています。
私は正しい方向に私を向けるのに役立ちます事前に感謝!
...
編集:URLエンコードではありませんReference.cs
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
//
// This source code was auto-generated by Microsoft.VSDesigner, Version 4.0.30319.42000.
//
#pragma warning disable 1591
namespace MyService.Search {
using System;
using System.Web.Services;
using System.Diagnostics;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
using System.ComponentModel;
// ..... snip other stuff ..... //
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.6.1055.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="searchSoap", Namespace="http://foo.bar/bazservice")]
public partial class search : System.Web.Services.Protocols.SoapHttpClientProtocol {
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://foo.bar/bazservice/Search", RequestNamespace="http://foo.bar/bazservice", ResponseNamespace="http://foo.bar/bazservice", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string ExecuteSearch(string sessionToken, string searchOptions, int pageNumber) {
object[] results = this.Invoke("Search", new object[] {
sessionToken,
searchOptions,
pageNumber});
return ((string)(results[0]));
}
public void ExecuteSearchAsync(string sessionToken, string searchOptions, int pageNumber) {
this.ExecuteSearchAsync(sessionToken, searchOptions, pageNumber, null);
}
// ..... snip other methods ..... //
}
}
#pragma warning restore 1591
[OK]を検索機能 – mikey
のコードを持っていますか、明確化のために....... –