本文介绍了如何在WCF中生成客户端类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有人都好,
我是WCF的新手.我不知道如何创建客户端类的想法.我在service1.cs中实现了一些方法.然后,我将此命令放入命令提示符"svcutil.exe http://localhost: 53391/Service.svc?wsdl.但是错误来了.请告诉我oto create client class这个概念
Iservice1.cs
Hai to all,
I am new to WCF.I don''t knew the idea on how to create a client class.I implement some method in service1.cs.Then afterwards i put this command in command prompt "svcutil.exe http://localhost:53391/Service.svc?wsdl".But the error is coming.Plz tell me the concept oto create client class
Iservice1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService3
{
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(string value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[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; }
}
}
}
service1.svc.cs
service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService3
{
// NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
public class Service1 : IService1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
推荐答案
这篇关于如何在WCF中生成客户端类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!