我有现有的从我们服务器的一个这是运行IIS 8 ASP.NET 4.5使用WAS(Windows激活服务)WSDL和XSD文件。我使用VS 2012的项目。我没有对WCF服务主机的原代码,所以我需要创建从现有的WSDL和XSD文件的WCF主机。
我有客户端代理代码已经即客户是部分已经完成。
我需要生成WCF服务主机将在IIS 8服务器从现有的WSDL和XSD文件被托管?不是客户端代理代码 - 我已经有完成。
我有以下文件
注:MyMainService.wsdl点mySubService.wsdl其中包含的代码来调用myFirstXSD.xsd和mySecondXSD.xsd我也有一个WSDL即myServiceSingleWSDL.wsdl
我通读了如何使用svcutil.exe的和Disco.exe,但我不知道怎么做是正确的。大多数类似于不回答这个问题,但只是去周围的问题。
请给一个一步一步的,如果你能包括的命令被用来做什么的。任何帮助将十分赞赏。
于是我运行下面的命令从上述文件SvcUtil工具/ MC /语言下面生成的代码:C#/out:IService1.cs /n:*,Contoso.WcfServiceHost MyMainService.wsdl MySubService.wsdl MyFirstXSD.xsd MySecondXSD.xsd
什么是从这里开始的下一步是什么?生成将在IIS 8托管WCF服务主机,以便客户端可以连接到它或使用它
这里生成的Web.config文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyService">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://contoso.com/MyService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService"
contract="IMyService" name="WSHttpBinding_IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
</system.serviceModel>
</configuration>
下面是产生Iservice1.cs文件
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18051
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Contoso.WcfServiceHost
{
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://contoso.com/MyService.svc", ConfigurationName = "IMyService")]
public interface IMyService
{
[System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Login", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LoginResponse")]
LoginResponse Login(LoginRequest request);
[System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Login", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LoginResponse")]
System.Threading.Tasks.Task<LoginResponse> LoginAsync(LoginRequest request);
[System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Logout", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LogoutResponse")]
LogoutResponse Logout(LogoutRequest request);
[System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Logout", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LogoutResponse")]
System.Threading.Tasks.Task<LogoutResponse> LogoutAsync(LogoutRequest request);
[System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/GetId", ReplyAction = "http://contoso.com/MyService.svc/IMyService/GetIdResponse")]
GetIdResponse GetId(GetIdRequest request);
[System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/GetId", ReplyAction = "http://contoso.com/MyService.svc/IMyService/GetIdResponse")]
System.Threading.Tasks.Task<GetIdResponse> GetIdAsync(GetIdRequest request);
}
[System.ServiceModel.MessageContractAttribute(WrapperName = "Login", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
public partial class LoginRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
public string login;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 1)]
public string password;
public LoginRequest()
{
}
public LoginRequest(string login, string password)
{
this.login = login;
this.password = password;
}
}
[System.ServiceModel.MessageContractAttribute(WrapperName = "LoginResponse", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
public partial class LoginResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
public System.Guid LoginResult;
public LoginResponse()
{
}
public LoginResponse(System.Guid LoginResult)
{
this.LoginResult = LoginResult;
}
}
[System.ServiceModel.MessageContractAttribute(WrapperName = "Logout", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
public partial class LogoutRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
public System.Guid sessionId;
public LogoutRequest()
{
}
public LogoutRequest(System.Guid sessionId)
{
this.sessionId = sessionId;
}
}
[System.ServiceModel.MessageContractAttribute(WrapperName = "LogoutResponse", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
public partial class LogoutResponse
{
public LogoutResponse()
{
}
}
[System.ServiceModel.MessageContractAttribute(WrapperName = "GetId", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
public partial class GetIdRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
public System.Guid sessionId;
public GetIdRequest()
{
}
public GetIdRequest(System.Guid sessionId)
{
this.sessionId = sessionId;
}
}
[System.ServiceModel.MessageContractAttribute(WrapperName = "GetIdResponse", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
public partial class GetIdResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
public long GetIdResult;
public GetIdResponse()
{
}
public GetIdResponse(long GetIdResult)
{
this.GetIdResult = GetIdResult;
}
}
public interface IMyServiceChannel : IMyService, System.ServiceModel.IClientChannel
{
}
public partial class MyServiceClient : System.ServiceModel.ClientBase<IMyService>, IMyService
{
public MyServiceClient()
{
}
public MyServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public MyServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public MyServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public MyServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public LoginResponse Login(LoginRequest request)
{
return base.Channel.Login(request);
}
public System.Threading.Tasks.Task<LoginResponse> LoginAsync(LoginRequest request)
{
return base.Channel.LoginAsync(request);
}
public LogoutResponse Logout(LogoutRequest request)
{
return base.Channel.Logout(request);
}
public System.Threading.Tasks.Task<LogoutResponse> LogoutAsync(LogoutRequest request)
{
return base.Channel.LogoutAsync(request);
}
public GetIdResponse GetId(GetIdRequest request)
{
return base.Channel.GetId(request);
}
public System.Threading.Tasks.Task<GetIdResponse> GetIdAsync(GetIdRequest request)
{
return base.Channel.GetIdAsync(request);
}
}
}
svcutil.exe的不会产生对你的服务代码(因为它听起来像你已经找到了)。
如果原来的服务创建或您所拥有的/你的公司,或者您必须对源代码的合法权利,你可以使用Reflector,JustDeCompile或类似工具(反射器免费试用,但你必须付出长期使用,JustDecompile是免费的,但不够灵活反射)扭转工程师DLL / EXE(假设你有访问的DLL / EXE文件)。
如果这不是一个选择,你可以看看契约优先发展,虽然我从来没有使用过它自己:
Schema-based Development with Windows Communication Foundation
我也看到Thinktecture的WSCF.blue,这可能是值得考虑的引用。