我试图使用Python的request包查询wcfweb服务。
我在WCF中创建了一个非常简单的web服务,遵循默认的VS模板:
[ServiceContract]
public interface IHWService
{
[OperationContract]
[WebInvoke(Method="GET", UriTemplate="SayHello", ResponseFormat=WebMessageFormat.Json)]
string SayHello();
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "GetData", ResponseFormat = WebMessageFormat.Json)]
string GetData(int value);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "GetData2", BodyStyle=WebMessageBodyStyle.Bare, RequestFormat=WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
在Python中,我设法调用前两个并轻松地获取数据。在
但是,我尝试调用第三个,它添加了复杂类型的概念。在
这是我的python代码:
^{pr2}$但是它不起作用,也就是说,如果我在GetDataUsingDataContract
方法中对VS进行细分,我会发现composite
参数是null
。我认为这是由于解析中的一个问题,但我不太清楚是什么问题。在
你看到明显的错误吗?在
你知道我如何在解析机制内调试吗?在
编辑:
以下是复杂类型定义:
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
您需要在POST body中发送JSON,但您将其附加到查询参数。在
请改用
data
,只对外部结构进行编码:如果对
cType
进行编码,则会发送一个JSON编码的字符串,该字符串包含另一个JSON编码的字符串,该字符串又包含您的cType
字典。在相关问题 更多 >
编程相关推荐