很抱歉打扰你们。
我将在服务器上使用WCF服务。该服务由外部创建。如果我在浏览器中查看它,那很好。请看下面的图片。
要使用它,我添加服务引用。使用网址http://wsvc01/BOERPI/BOERPI.svc
然后我通过代码实例化代理。
BOERPI.PostPhoneCallResponse client = null;
client = new BOERPI.PostPhoneCallResponse();
double x = client.ActualCallCharge; // suppose to get a proper value but not
该服务的一些代码是:
[ServiceContract]
public interface iBOERPI
{
[OperationContract]
PostPhoneCallResponse PostPhoneCall(PostPhoneCallRequest objCDRRequest);
[DataContract]
public class PostPhoneCallResponse
{
[DataMember]
public double ActualCallCharge = -1.0;
我认为服务代码是100%正确的,当我使用服务时有什么不对吗?
当我正确点击PostPhoneCallResponse的定义时,它是:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="PostPhoneCallResponse", Namespace="http://schemas.datacontract.org/2004/07/nsBOERPI")]
[System.SerializableAttribute()]
public partial class PostPhoneCallResponse : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private double ActualCallChargeField;
感谢。
答案 0 :(得分:1)
client = new BOERPI.PostPhoneCallResponse();
您正尝试在此使用DataContract
而不是服务客户端。
在服务引用下检查您在客户端应用程序中使用的服务名称 使用它:
例如
using(var client = new BingMapsGeocodeService()) // This should be your service client name
{
}
<强>更新强>
使用请求和响应对象发送和接收消息:
您需要根据操作显示创建请求对象:
var request = new PostPhoneCallRequest(){ // populate all your properties you need to send to the service};
var client = new BOERPI.MyClient(); // Instantiate your client with the name you have given for your service client.
PostPhoneCallResponse response = client.PostPhoneCall(request); // You are sending your request and getting a response as PostPhoneCallResponse object