Announcement

Collapse
No announcement yet.

Veröffentlichen eines Webservice

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Veröffentlichen eines Webservice

    Hallo zusammen,

    ich verzweifle gerade an folgender Sache:
    Ich habe einen Webservice aus einer WSDL generieren lassen. Ich habe auch die Impementierung dazu erstellt. Die Frage ist wie ich denn nun diesen Service auf dem Tomcat Server publiziere.
    Ich entwickle gleichzeitig in Java und da veröffentliche ich den Service ganz einfach über
    private static String address = "http://127.0.0.1:8080/WebserviceSOAP";
    Object implementor = new WebserviceImpl();
    this.endPoint = Endpoint.publish(address, implementor);

    Wie schaffe ich das gleiche denn nun in C#?

    Bin dankbar für jeden Hilfe!

  • #2
    ich hoffe das wird dir helfen...

    nicht vergessen einen projektverweis von system.servicemodel zu machen :-)

    [highlight=c#]
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    using Service1;

    namespace Service1
    {
    class Programm
    {
    static void Main(string[] args)
    {
    WS2007HttpBinding WsReliableBinding = new WS2007HttpBinding();
    WsReliableBinding.ReliableSession.Enabled = true;
    Uri uri = new Uri("http://localhost:8080");
    using (ServiceHost selfHost = new ServiceHost(typeof(Service1), uri))
    {
    selfHost.AddServiceEndpoint(typeof(IService1), WsReliableBinding, "Service");
    ServiceMetadataBehavior smb = selfHost.Description.Behaviors.Find<ServiceMetadat aBehavior>();
    if (smb == null)
    smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    selfHost.Description.Behaviors.Add(smb);
    selfHost.AddServiceEndpoint(ServiceMetadataBehavio r.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "Mex");

    selfHost.Open();
    Console.WriteLine("Service ist gestartet...");
    Console.ReadLine();
    selfHost.Close();
    }
    }
    }
    }
    [/highlight]


    wenn du eine andere art der datenübermittlung möchtest, musst du die Zeile 12 und 13 überarbeiten, der rest sollte gleich bleiben.

    MFG Nooa

    Comment


    • #3
      Weiß jetzt nicht so ganz was ich in den Zeilen 12 und 13 anpassen muss um es korrekt für die WSDL einzustellen. Daher hier mal eben die WSDL:
      Code:
      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:8080/TaPConnectorWS_tapside/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TaPConnectorWS_tapside" targetNamespace="http://localhost:8080/TaPConnectorWS_tapside/">
          <wsdl:types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://localhost:8080/TaPConnectorWS_tapside/">
      	<xsd:complexType name="CellSet">
      		<xsd:sequence>
      			<xsd:element name="cells" type="tns:Cell" maxOccurs="unbounded" minOccurs="1"></xsd:element>
      		</xsd:sequence>
      	</xsd:complexType>
      
      	<xsd:complexType name="Node">
      		<xsd:attribute name="name" type="xsd:string"></xsd:attribute>
      		<xsd:attribute name="displayName" type="xsd:string"></xsd:attribute>
      		<xsd:attribute name="levelName" type="xsd:string"></xsd:attribute>
      	</xsd:complexType>
      
      	<xsd:complexType name="Level">
      		<xsd:attribute name="name" type="xsd:string"></xsd:attribute>
      	</xsd:complexType>
      	
                  <xsd:complexType name="MeasureValue">
                  	<xsd:attribute name="measureName" type="xsd:string"></xsd:attribute>
                  	<xsd:attribute name="value" type="xsd:double"></xsd:attribute>
                  </xsd:complexType>
      
                  <xsd:complexType name="Cell">
                  	<xsd:sequence>
                  		<xsd:element name="nodes" type="tns:Node"
                  			maxOccurs="unbounded" minOccurs="1">
                  		</xsd:element>
                  		<xsd:element name="measureValues" type="tns:MeasureValue" maxOccurs="unbounded" minOccurs="1"></xsd:element>
                  	</xsd:sequence>
                  </xsd:complexType>
      </xsd:schema></wsdl:types>
        <wsdl:message name="SendDataRequest">
          <wsdl:part name="cellset" type="tns:CellSet"/>
        </wsdl:message>
        <wsdl:portType name="TaPConnectorWS_tapside">
          <wsdl:operation name="SendData">
            <wsdl:input message="tns:SendDataRequest"/>
          </wsdl:operation>
        </wsdl:portType>
        <wsdl:binding name="TaPConnectorWS_tapsideSOAP"
        	type="tns:TaPConnectorWS_tapside">
        	<soap:binding style="rpc"
        		transport="http://schemas.xmlsoap.org/soap/http" />
        	<wsdl:operation name="SendData">
        		<soap:operation
        			soapAction="http://localhost:8080/TaPConnectorWS_tapside/SendData" />
        		<wsdl:input>
        			<soap:body
        				namespace="http://localhost:8080/TaPConnectorWS_tapside/"
        				use="literal" />
        		</wsdl:input>
        	</wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="TaPConnectorWS_tapside">
          <wsdl:port binding="tns:TaPConnectorWS_tapsideSOAP" name="TaPConnectorWS_tapsideSOAP">
            <soap:address location="http://localhost:8080/"/>
          </wsdl:port>
        </wsdl:service>
      </wsdl:definitions>
      Bekomme gerade folgende Fehlermeldung:
      Der Vertragstyp ist nicht TaP.Webservice.ITaPConnectorWS_tapsideSOAP mit dem ServiceContractAttribute attributiert. Um einen gültigen Vertrag zu definieren, muss der angegebene Typ (entweder Vertragsschnittstelle oder Dienstklasse) mit dem ServiceContractAttribute attributiert werden.

      Comment

      Working...
      X