当前位置: 首页 > 知识库问答 >
问题:

svcutil无法为自托管wcf服务生成接口

上官波鸿
2023-03-14

你能帮我解决我的错误吗?

我正在WinForm程序集中自托管WCF,并尝试生成客户端应用程序配置和服务接口。我正在执行svcutilhttp://localhost:8880/MyOwnWCFService//Language=c#/t:Code/out:c:\Service\ServiceProxy。配置:C:\Service\ServiceProxy。在VS2015 developer命令提示符中进行配置。

我发现以下错误:

错误:无法从获取元数据http://localhost:8880/MyOwnWCFService/

如果这是您有权访问的Windows(R)通信基金会服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455.的MSDN留档

WS元数据交换错误URI:http://localhost:8880/MyOwnWCFService/

Metadata contains a reference that cannot be resolved: 'http://localhost:8880/MyOwnWCFService/'.

Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:8880/MyOwnWCFService/.  The client and service bindings may be mismatched.

The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..

HTTP GET错误URI:http://localhost:8880/MyOwnWCFService/

There was an error downloading 'http://localhost:8880/MyOwnWCFService/'.

#内容{FONT-SIZE:0.7em;垫底:2em;MARGIN-LEFT:30px}BODY{MARGIN-TOP:0px;MARGIN-LEFT:0px;颜色:#000000;FONT-FAMILY:Verdana;背景颜色:白色}P{MARGIN-TOP:0px;MARGIN-BOTTOM:12px;颜色:#000000;FONT-FAMILY:Verdana}PRE{BORDER-右:#f0f0e0 1px固体;垫底-右:5px;边框-顶部:#f0f0e0 1px固体;马林-顶部:-5px;垫底-左:5px;字体大小:1.2em;垫底:5px;边框-底部:0px;填充底部:3px;左边距:-30px;宽度:100%;颜色:#ffffff;填充顶部:10px;字体-家庭:塔霍马;背景-颜色:#003366}. intro{左边距:-15px}服务

如果您需要更多帮助,请键入“svcutil/?”

我的自托管代码

系统服务模型。频道。Binding MexHttpBinding=MetadataExchangeBindings。CreateMexHttpBinding();

               String baseAddress = "http://localhost:8880/MyOwnWCFService/";
                NetTcpBinding tcpbinding = new NetTcpBinding(SecurityMode.None);
                tcpbinding.Name = "SEMSIntegration_NetTcpBinding_iSEMSIntegrationWCFService";
                tcpbinding.OpenTimeout = new TimeSpan(00, 01, 00);
                tcpbinding.CloseTimeout = new TimeSpan(00, 01, 00);
                tcpbinding.ReceiveTimeout = new TimeSpan(00, 01, 00);
                tcpbinding.SendTimeout = new TimeSpan(00, 01, 00);
                tcpbinding.TransactionFlow = false;
                tcpbinding.TransferMode = TransferMode.Buffered;
                tcpbinding.TransactionProtocol = TransactionProtocol.OleTransactions;
                tcpbinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                tcpbinding.ListenBacklog = 10;
                tcpbinding.MaxBufferPoolSize = 524288;
                tcpbinding.MaxBufferSize = 524288;
                tcpbinding.MaxConnections = 100;
                tcpbinding.MaxReceivedMessageSize = 524288;

                WindowState = FormWindowState.Minimized;
                SEMSService = new MyOwnWCFService();
                SEMSHost = new ServiceHost(SEMSService, new Uri(baseAddress));

                ServiceMetadataBehavior smb = SEMSHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
                // If not, add one
                if (smb == null)
                {
                    smb = new ServiceMetadataBehavior();
                }
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                SEMSHost.Description.Behaviors.Add(smb);
                SEMSHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());

                SEMSHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());
                SEMSHost.AddServiceEndpoint(typeof(iSEMSIntegrationWCFService), new BasicHttpBinding(), "http://localhost:8880/MyOwnWCFService");
                SEMSHost.AddServiceEndpoint(typeof(iSEMSIntegrationWCFService), tcpbinding, "net.tcp://localhost:8888/MyOwnWCFService");
                SEMSHost.AddServiceEndpoint("IMetadataExchange", MexHttpBinding, "mex");

                SEMSHost.Open();

共有1个答案

辛意智
2023-03-14
This is because you are getting the error:

System.Runtime.Serialization.InvalidDataContractException: Type 'System.Windows.Forms.Menu' cannot be serialized.

See browser exception detail:

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
 contract: http://tempuri.org/:iSEMSIntegrationWCFService ----> System.Runtime.Serialization.InvalidDataContractException: Type 'System.Windows.Forms.Menu' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
   at System.Runtime.Serialization.ClassDataContract.ClassDataContractCriticalHelper..ctor(Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
   at System.Runtime.Serialization.DataContractSet.GetDataContract(Type clrType)
   at System.Runtime.Serialization.DataContractSet.GetMemberTypeDataContract(DataMember dataMember)
   at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
   at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)
   at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
   at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)
   at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
   at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)
   at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
   at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)
   at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
   at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)
   at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)
   at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)
   at System.Runtime.Serialization.DataContractSet.Add(Type type)
   at System.Runtime.Serialization.XsdDataContractExporter.Export(Type type)
   at System.ServiceModel.Description.MessageContractExporter.ExportType(Type type, String partName, String operationName, XmlSchemaType& xsdType)
   at System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32 messageIndex, Object state)
   at System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32 messageIndex, Object state)
   at System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
   at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext)
   at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)
   --- End of inner ExceptionDetail stack trace ---
   at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)
   at System.ServiceModel.Description.WsdlExporter.CallExportContract(WsdlContractConversionContext contractContext)
   at System.ServiceModel.Description.WsdlExporter.ExportContract(ContractDescription contract)
   at System.ServiceModel.Description.WsdlExporter.ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, BindingParameterCollection bindingParameters)
   at System.ServiceModel.Description.WsdlExporter.ExportEndpoints(IEnumerable`1 endpoints, XmlQualifiedName wsdlServiceQName, BindingParameterCollection bindingParameters)
   at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata()
   at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()
   at System.ServiceModel.Description.ServiceMetadataExtension.get_Metadata()
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest)
   at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)
   at SyncInvokeGet(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)


Contract Definition:

<system.serviceModel>
  <services>
    <service name="myService" behaviorConfiguration="MyDefaultBehaviour">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8880/MyOwnWCFService/" />
        </baseAddresses>
      </host>

      <endpoint
        address=""
        binding="basicHttpBinding"
        contract="iSEMSIntegrationWCFService" />

      <endpoint
        address="mex"
        binding="mexHttpBinding"
        contract="IMetaDataExchange" />
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name ="MyDefaultBehaviour">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceThrottling maxConcurrentCalls="1" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
 类似资料:
  • 我有一个WCF服务,我试图在Sitecore 7.1应用程序中托管。具有相同配置的Web服务在空白Asp.net应用程序中托管时运行良好。但是当尝试从Sitecore应用程序运行它时,它不起作用(下面的错误)。我也尝试了这些解决方案,但没有运气。我不确定它们是否应该适用于最新版本的Sitecore。 https://adeneys.wordpress.com/2008/10/17/make-sit

  • 我可以在我自己的电脑上使用这个程序,但是我不能在服务器上使用。 服务器使用最高权限管理员打开程序。 具有的服务器WCF HTTP激活功能。NET4。5号门开着。 服务器endpoint地址使用"http://localhost",如下所示 endpoint地址="http://localhost"绑定="basicHttpBind"bindingConfiguration="NewBinding0

  • 当你想要分享你代码给其他人,或者是你需要在另外一台电脑上工作时,托管代码就会是一个非常重要的话题。基本上代码托管有两种不同的形式: do-it-yourself(建立一个自己的)或者 leave-me-in-peace(使用第三方提供的平台,不麻烦自己)。 (A) Do-It-Yourself 把你的 Git 仓库托管在你自己的服务器上会有很多的优点: 可以节省你花在代码托管服务上的费用。 你的代

  • 问题内容: 我想寻求有关WCF服务的正确端点配置的指导,以使Flash应用能够使用它。 谢谢,基思·拉尔 问题答案: 好了,您应该从webHttpBinding开始,并且自然也需要应用webHttp行为。然后,您只需要弄清楚要使用的序列化格式。Flash可以执行JSON或XML,因此您需要确定自己喜欢哪种,然后设置适用于您的操作的WebInvokeAttribute的ReqeustFormat /

  • 无法连接Openshift集群上托管的jenkins主服务器。握手后终止,出现以下错误: 我为jenkins-jnlp服务添加了路由,但我无法公开端口,我一直在尝试配置nodePort,但还无法存档。欢迎任何帮助!谢谢。

  • 无法连接Openshift集群上托管的jenkins主服务器。握手后终止,出现以下错误: 我正在连接窗口机器(VM)作为从属设备。有什么建议吗?蒂亚。