如何为WCf服务生成存根 [英] How to generate stubs for WCf Services

查看:114
本文介绍了如何为WCf服务生成存根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找解决方案如何存根服务



情景是我有服务



[ServiceContract]

公共接口IService1

{

[OperationContract]

string TestMethod( string name);

}





公共类上下文:IService1

{

公共字符串TestMethod(字符串名称)

{

//这里有些代码

//返回someString

}

}





如何为此场景创建存根????

请帮忙,因为我是新手...



先谢谢

I'm stuck in finding the solution how to stub a service

The Scenario is I have a service

[ServiceContract]
public interface IService1
{
[OperationContract]
string TestMethod(string Name);
}


public class Context : IService1
{
public string TestMethod(string name)
{
//some code here
//return someString
}
}


How I can create stub for this scenario???
Please help as I'm new in it...

Thanks In Advance

推荐答案

您应该使用Visual Studio并让它为您生成存根!之后,您可以创建一个测试项目并添加对WCF服务的引用,也可以使用Visual Studio和Solution Explorer。
You should use Visual Studio and let it to generate the stub for you! After that you could create a test project and add reference to your WCF service, also by using Visual studio and Solution Explorer.


如果要在IIS中托管服务,则创建一个svc文件并将其指向IService1。



如果你想要一个代理类,那么你可以使用svcutil。

在你使用svcutil之前,你需要暴露mex端点,以便wsdl可用。

然后使用svcutil生成存根。



If you want to host the service in IIS, then create a svc file and point it to IService1.

If you want a proxy class then you can use svcutil.
Before you use svcutil, you need to expose the mex endpoint, so that the wsdl is available.
then use svcutil to generate the stub.

svcutil http://servicepath?wsdl



或者如果你把wsdl文件保存在某些地方然后尝试


or if you have the wsdl file saved some where then try

svcutil filename.wsdl

这篇关于如何为WCf服务生成存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆