Ошибка svcutil для генерации интерфейсов для самостоятельной службы wcf - PullRequest
0 голосов
/ 26 сентября 2018

Не могли бы вы помочь мне исправить мои ошибки?

Я сам размещаю WCF в сборке WinForm и пытаюсь сгенерировать клиентский app.config и интерфейс службы.Я выполняю svcutil http://localhost:8880/MyOwnWCFService/ / Language = c # / t: Code /out:C:\Service\ServiceProxy.cs /config:C:\Service\ServiceProxy.config в командной строке разработчика VS2015.

Я получаю следующие ошибки:

Ошибка: невозможно получить метаданные из http://localhost:8880/MyOwnWCFService/

Если это служба Windows (R) Communication Foundation, к которой у вас есть доступ, проверьте, пожалуйста,Вы включили публикацию метаданных по указанному адресу.Для получения справки о включении публикации метаданных см. Документацию MSDN по адресу http://go.microsoft.com/fwlink/?LinkId=65455.

URI ошибки обмена метаданными WS: 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'..

URI ошибки HTTP GET: http://localhost:8880/MyOwnWCFService/

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

Запрос не выполнен с сообщением об ошибке:

# content {FONT-SIZE: 0.7em;Нижняя часть: 2em;MARGIN-LEFT: 30px} ТЕЛО {MARGIN-TOP: 0px;MARGIN-LEFT: 0px;ЦВЕТ: # 000000;Шрифтовая семья: Вердана;ЦВЕТ ФОНА: белый} P {MARGIN-TOP: 0px;Дно: 12px;ЦВЕТ: # 000000;FONT-FAMILY: Verdana} PRE {ПРАВО ГРАНИЦЫ: # f0f0e0 1px solid;ВПРАВО-ПРАВО: 5px;BORDER-TOP: # f0f0e0 1px solid;MARGIN-TOP: -5px;PADDING-LEFT: 5 пикселей;Размер шрифта: 1.2em;Нижняя часть: 5px;ГРАНИЦА-ВЛЕВО: # f0f0e0 1px solid;PADDING-TOP: 5 пикселей;Дно границы: # f0f0e0 1px solid;FONT-FAMILY: Курьер Новый;ЦВЕТ ФОНА: # e5e5cc} .heading1 {MARGIN-TOP: 0px;PADDING-LEFT: 15 пикселей;Вес шрифта: нормальный;Размер шрифта: 26 пикселей;Дно: 0px;Нижняя часть: 3 пикселя;MARGIN-LEFT: -30px;ШИРИНА: 100%;ЦВЕТ: #ffffff;PADDING-TOP: 10 пикселей;Шрифтовая семья: Tahoma;ЦВЕТ ФОНА: # 003366} .intro {MARGIN-LEFT: -15px} ServiceService

Серверу не удалось обработать запрос из-за внутренней ошибки.Для получения дополнительной информации об ошибке либо включите IncludeExceptionDetailInFaults (либо из ServiceBehaviorAttribute, либо из поведения конфигурации) на сервере, чтобы отправить информацию об исключении обратно клиенту, либо включите трассировку в соответствии с документацией Microsoft .NET Framework SDK ипроверьте журналы трассировки сервера. -.

Если вам нужна дополнительная помощь, введите "svcutil /?"

Код моего собственного хостинга:

Система.ServiceModel.Channels.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 Ответ

0 голосов
/ 27 сентября 2018
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>
...