我有下面的代碼:如何以編程方式創建BasicHttpBinding?
BasicHttpBinding binding = new BasicHttpBinding();
Uri baseAddress = new Uri ("URL.svc");
EndpointAddress endpointAddress = new EndpointAddress (baseAddress);
var myChannelFactory = new ChannelFactory<IMyInterface> (binding, endpointAddress);
IMyInterface client = null;
try
{
client = myChannelFactory.CreateChannel();
var a = client.WsFunction ("XXXXXX");
((ICommunicationObject)client).Close();
}
catch
{
if (client != null)
{
((ICommunicationObject)client).Abort();
}
}
其中 「IMyInterface的」 是,我的WS實現接口。例如:
[ServiceContract]
public interface IMyInterface
{
[OperationContract]
Result WsFunction1 (string param);
[OperationContract]
Result WsFunction2 (string param);
[OperationContract]
Result WsFunction3 (string param);
}
,並返回是這樣的:
[DataContract]
public class Result
{
string a = "";
string b = "";
[DataMember]
public string A
{
get { return a; }
set { a = value; }
}
[DataMember]
public string B
{
get { return b; }
set { b = value; }
}
}
當我運行這段代碼時,我可以到達WS,但我永遠無法獲得結果填寫。
我在做什麼錯?
提前致謝!
這不會編譯,小a是字符串類型,大a是bool類型。 –
這是因爲我改變了名字......但實際上它編譯和WS收到消息......但我不能得到結果.. – Crasher
結果名稱空間是一個問題的罪魁禍首,但我會從嗅探流量開始http調試器。 –