相关疑难解决方法(0)

WCF Rest涉及复杂类型的参数

设置使用webHttpBinding的WCF服务...我可以从XML方法返回复杂类型.如何将复杂类型作为参数?

[ServiceContract(Name = "TestService", Namespace = "http://www.test.com/2009/11")]
public interface ITestService
{
    [OperationContract]
    [WebInvoke(Method = "POST", 
               BodyStyle = WebMessageBodyStyle.Bare, 
               UriTemplate = "/Person/{customerAccountNumber}, {userName}, {password}, {PersonCriteria}")]
    Person SubmitPersonCriteria(string customerAccountNumber, 
                                string userName, 
                                string password, 
                                PersonCriteria details);
}
Run Code Online (Sandbox Code Playgroud)

由于UriTemplate只允许字符串,最佳做法是什么?这个想法是客户端应用程序将向服务发布请求,例如一个人的搜索条件.该服务将使用包含XML数据的相应对象进行响应.

xml rest wcf

7
推荐指数
1
解决办法
2万
查看次数

400 错误请求将 xml 负载发送到 WCF REST 服务

我知道有一些帖子询问了 400 错误,我相信我已经阅读了所有帖子,但我认为我面临的问题是不同的。

这是我的 WCF 服务合同

[WebInvoke(UriTemplate = "/cust_key/{key}/prod_id/{id}", 
           Method = "POST",
           BodyStyle = WebMessageBodyStyle.Bare, 
           RequestFormat = WebMessageFormat.Xml, 
           ResponseFormat = WebMessageFormat.Xml)]
Stream GetData(string key, string id, string data);
Run Code Online (Sandbox Code Playgroud)

这是我用来将请求发送到我的休息 svc 的代码

request.RequestUri = 
     new Uri("http://localhost:3138/v1/cust_key/company1/prod_id/testProductID");
request.ContentType = "application/xml";
request.HttpMethod = "POST";

string xml = 
         @"<Product><name>dell 400</name><price>400 dollars</price></Product>";

byte[] message = Encoding.ASCII.GetBytes(xml);
string data = Convert.ToBase64String(message);
response = request.MakeWebRequest(null, data);
Run Code Online (Sandbox Code Playgroud)

这给了我 400 个错误的请求错误。我尝试将 xml 字符串更改为以下两个,但它们也会产生 400 错误

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
       <![CDATA[<Product><name>dell 400</name><price>400 dollars</price></Product>]]>
</string>
Run Code Online (Sandbox Code Playgroud)

或者

<![CDATA[<Product><name>dell 400</name><price>400 dollars</price></Product>]]>
Run Code Online (Sandbox Code Playgroud)

如果有效负载 xml 是空字符串,则一切正常并返回 200。谁能帮我一把? …

.net c# xml rest wcf

5
推荐指数
1
解决办法
4703
查看次数

标签 统计

rest ×2

wcf ×2

xml ×2

.net ×1

c# ×1