ServiceStack:VS 2012添加服务引用

时间:2015-03-03 14:30:28

标签: c# soap servicestack

我在向soap端点添加服务引用时遇到问题。我甚至尝试在SS网站http://mono.servicestack.net/soap11上添加hello示例的地址,并且无法生成wsdl。我的所有dtos(在我的项目中)都装饰有数据合同/成员。我还将程序集更改为指向目标命名空间。我尝试将其添加为Web引用,并在引用程序集中标记重用类型,但仍然没有运气。有什么事我忘记了吗?如果需要更多信息,请与我们联系。

using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WILP_API
{
    public class ApplicationHost : AppHostBase
    {
        public ApplicationHost() : base("GreetingService", typeof(GreetingService).Assembly) { }

        public override void Configure(Funq.Container container)
        {
            //throw new NotImplementedException();
        }
    }
}​
using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;

namespace WILP_API
{
    [Route("/hello/{Name}","GET")]
    [DataContract(Namespace="WILP_API")]
    public class GreetingRequest
    {
        [DataMember]
        public string Name { get; set; }
    }
}
using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;

namespace WILP_API
{
    [Route("/hello/{Name}", "GET")]
    [DataContract(Namespace="WILP_API")]
    public class GreetingResponse
    {
        [DataMember]
        public string Result { get; set; }
    }
}​
using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WILP_API
{
    public class GreetingService : IService
    {
        public GreetingResponse Any(GreetingRequest request)
        {
            GreetingResponse response = new GreetingResponse();
            response.Result = "Hello, " + request.Name + "!";
            return response;
        }
    }
}​
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WILP_API")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WILP_API")]
[assembly: AssemblyCopyright("Copyright ©  2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("133bdb3e-442d-45ad-9cc2-02fbcd50c8ac")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ContractNamespace("http://schemas.servicestack.net/types",
           ClrNamespace = "WILP_API")]
[assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "ServiceStack")]
[assembly: ContractNamespace("http://schemas.servicestack.net/types", ClrNamespace = "ServiceStack.Client")]​

错误:

  

错误5自定义工具错误:无法为服务生成代码   参考' ServiceReference3'。请检查其他错误和警告   消息了解详情。

     

警告3自定义工具警告:无法导入wsdl:binding详细信息:   导入wsdl:binding的wsdl:portType时出错   依赖于。 XPath到wsdl:portType:   // WSDL:定义[@targetNamespace =' http://schemas.servicestack.net/types'] / WSDL:portType的[@name =' ISyncReply']   XPath到错误源:   // wsdl:definitions [@targetNamespace =' http://schemas.servicestack.net/types'] / wsdl:binding [@name =' BasicHttpBinding_ISyncReply']

     

警告4自定义工具警告:无法导入wsdl:port详细信息:那里   导入wsdl:port依赖的wsdl:binding时出错   上。 XPath到wsdl:binding:   // WSDL:定义[@targetNamespace =' http://schemas.servicestack.net/types'] / WSDL:结合[@name =' BasicHttpBinding_ISyncReply']   XPath到错误源:   // WSDL:定义[@targetNamespace =' http://schemas.servicestack.net/types'] / WSDL:服务[@name =' SyncReply'] / WSDL:端口[@name =&# 39; BasicHttpBinding_ISyncReply']

     

警告2自定义工具警告:无法导入wsdl:portType详细信息:An   运行WSDL导入扩展时抛出异常:   System.ServiceModel.Description.DataContractSerializerMessageContractImporter   错误:加载提供的XSD文档时出现问题:a   引用名为' GreetingRequest'的架构元素。和   命名空间' http://schemas.servicestack.net/types'不可能   已解决,因为无法找到元素定义   targetNamespace' http://schemas.servicestack.net/types'的架构。   请检查提供的XSD文档,然后重试。 XPath到错误   资源:   // WSDL:定义[@targetNamespace =' http://schemas.servicestack.net/types'] / WSDL:portType的[@name =' ISyncReply']

2 个答案:

答案 0 :(得分:1)

您应该确保只有single WSDL Namespace用于所有DTO。由于ServiceStack内置DTO已经使用http://schemas.servicestack.net/types进行了最简单的定义,因此建议您坚持使用[ContractNamespace]属性中的Assembly.cs属性。 {1}},例如:

[assembly: ContractNamespace("http://schemas.servicestack.net/types",
           ClrNamespace = "WILP_API")]

这将适用于WILP_API名称空间下该大会中的所有DTO,因此他们不再需要在DTO上定义名称空间,例如:

[Route("/hello/{Name}","GET")]
[DataContract]
public class Greeting : IReturn<GreetingResponse>
{
    [DataMember]
    public string Name { get; set; }
}

[DataContract]
public class GreetingResponse
{
    [DataMember]
    public string Result { get; set; }
}

此外,只有请求DTO使用[Route]属性。您还应该关注Greeting/GreetingResponse Request/Response DTO Naming Convention

更改WSDL命名空间

虽然如果您必须更改它,建议坚持使用默认的ServiceStack命名空间,但您还需要在HostConfig中配置不同的命名空间,例如:

SetConfig(new HostConfig {
    WsdlServiceNamespace = "http://new.namespace.com",
});

Add ServiceStack Reference

不应使用SOAP端点和WSDL,而应考虑使用提供大量ServiceStack's new Add ServiceStack Referenceadvantages over WCF's SOAP Add Service Reference

答案 1 :(得分:0)

我最近才意识到这一点,我想特别扩展上述答案。在我的情况下,结果是100%与使用的命名约定有关。

当SS生成wsdl时,推荐的命名约定here在某种程度上得到强制执行。我不确定它是否是故意或错误,但结束请求DTO的“请求”(至少截至2017年1月)会导致这三个警告,并在VS中添加标准.Net服务引用时失败。