1

このような WebInvoke メソッドがあります。

[OperationContract]

    [WebInvoke(

        Method = "POST",
        UriTemplate = "/go",
        BodyStyle = WebMessageBodyStyle.Bare,
        RequestFormat = WebMessageFormat.Xml,
        ResponseFormat = WebMessageFormat.Xml

    )]       
    string go(string name);

そして、私はこのようにデータを投稿します;

System.Net.WebClient client = new System.Net.WebClient();

        string reply = client.UploadString(
            "http://localhost/HelloService/Service.svc/go",
            "POST",
            aString);

問題は、このような uri テンプレートを使用せずにgo()メソッドで投稿されたメッセージからデータを取得する方法です。

UriTemplate = "/go({name})"

大量のデータを送りたいのにuriテンプレートでは送れないので

4

2 に答える 2

1

これが解決策です。

[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
Method = "POST",
UriTemplate="/go"
)]  
string MyWebServiceMethod(string name);

HTTPPOSTリクエストは;

POST /go Modify HTTPS/1.1
Content-Type: application/json; charset=utf-8
Host: WebserviceURL
Content-Length: length

{"name":"someName"}
于 2009-12-19T14:03:13.457 に答える
0

にアクセスできますSystem.Web.HttpContext.Currentか?

System.Web.HttpContext.Current.Request.Form を試すか、要求フォーマットに XML を使用しているように見えるので、要求ストリームから XElement または XmlDocument を読み込んでみてください。

(ここではメソッドが間違っている可能性がありますが、リクエスト オブジェクトのどこかに存在します) // .NET 4.0 のみ

XElement el = XElement.Load(HttpContext.Current.Request.GetRequestStream());
于 2009-11-25T12:45:04.720 に答える