U prevođenju na: German Spanish Italian French Greek Hungarian
Krapanj Spužvari Gdje smo O samostanu Zar je to kraj
 
Dodatak sa primjerom Web Servisa:

 

Primjer 1.: zaprezentaciju.asmx

using System;

using System.Web;

using System.Web.Services;

 

[WebService

 (Name="Za prezentaciju Web Servis",

 Description="Koliko je sati?",

 Namespace="ZaPrezentaciju")]

public class WebServis1 : WebService

 [WebMethod]

 public string TocnoVrijeme()

 {

 return "Točno vrijeme: "

 + System.DateTime.Now;

 }

}

 

Primjer 2. Web Aplikacije za korištenje Web servisa

<%@ Page Language="C#" %>

<script runat="server">

ZaPrezentaciju.ZaprezenzacijuWebServis ws = new ZaPrezentaciju.ZaprezentacijuWebServis();

void Button1_Click(

 object sender,

 EventArgs e)

 {

 TextBox1.Text =

 ws.TocnoVrijeme();

 }

</script>

<html>

<head>

<title>Test za prezentaciju</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">

</head>

<body>

<h1>Test WebService

</h1>

<form runat="server">

<asp:TextBox

id="TextBox1"

runat="server"

BorderStyle="Solid"

Columns="30">

</asp:TextBox>

<asp:Button

id="Button1"

onclick="Button1_Click"

runat="server"

Text="Koliko je sati ?"

BackColor="#FFFFC0">

</asp:Button>

</form>

</body>

</html>

 

 

Primjer 3. Proxy klasa generiranog sa wsdl alatom

//------------------------------------------------------------------------------

// <autogenerated>

// This code was generated by a tool.

// Runtime Version: 1.1.4322.573

//

// Changes to this file may cause incorrect behavior and will be lost if

// the code is regenerated.

// </autogenerated>

//------------------------------------------------------------------------------

//

// This source code was auto-generated by wsdl, Version=1.1.4322.573.

//

using System.Diagnostics;

using System.Xml.Serialization;

using System;

using System.Web.Services.Protocols;

using System.ComponentModel;

using System.Web.Services;

 

/// <remarks/>

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.ComponentModel.DesignerCategoryAttribute("code")]

[System.Web.Services.WebServiceBindingAttribute(Name="Za prezentaciju Web ServisSoap",

Namespace="ZaPrezentaciju")]

public class ZaprezentacijuWebServis : System.Web.Services.Protocols.SoapHttpClientProtocol {

 

 /// <remarks/>

 public ZaprezentacijuWebServis() {

 this.Url = "http://localhost/WebServis/zaprezentaciju.asmx";

 }

 

 /// <remarks/>

 [System.Web.Services.Protocols.SoapDocumentMethodAttribute("ZaPrezentaciju/TocnoVrijeme",

RequestNamespace="ZaPrezentaciju", ResponseNamespace="ZaPrezentaciju",

Use=System.Web.Services.Description.SoapBindingUse.Literal,

ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

 public string TocnoVrijeme() {

 object[] results = this.Invoke("TocnoVrijeme", new object[0]);

 return ((string)(results[0]));

 }

 /// <remarks/>

 public System.IAsyncResult BeginTocnoVrijeme(System.AsyncCallback callback, object asyncState{

 return this.BeginInvoke("TocnoVrijeme", new object[0], callback, asyncState);

 }

 

 /// <remarks/>

 public string EndTocnoVrijeme(System.IAsyncResult asyncResult) {

 object[] results = this.EndInvoke(asyncResult);

 return ((string)(results[0]));

 }

}

 

Primjer 4. Primjer SOAP protokola

 

Za prezentaciju Web Servis

 

Click here for a complete list of operations.

TocnoVrijeme

Test

To test the operation using the HTTP POST protocol, click the 'Invoke' button.

 

SOAP

The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.

POST /WebServis/zaprezentaciju.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "ZaPrezentaciju/TocnoVrijeme"
 
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <TocnoVrijeme xmlns="ZaPrezentaciju" />
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
 
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <TocnoVrijemeResponse xmlns="ZaPrezentaciju">
      <TocnoVrijemeResult>string</TocnoVrijemeResult>
    </TocnoVrijemeResponse>
  </soap:Body>
</soap:Envelope>

HTTP POST

The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.

POST /WebServis/zaprezentaciju.asmx/TocnoVrijeme HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
 
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
 
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="ZaPrezentaciju">string</string>

 

Primjer 5. Primjer WSDL dokumenta našeg servisa

 

  <?xml version="1.0" encoding="utf-8" ?>

- <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="ZaPrezentaciju"

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"

xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="ZaPrezentaciju"

xmlns="http://schemas.xmlsoap.org/wsdl/">

- <types>

- <s:schema elementFormDefault="qualified" targetNamespace="ZaPrezentaciju">

- <s:element name="TocnoVrijeme">

  <s:complexType />

  </s:element>

- <s:element name="TocnoVrijemeResponse">

- <s:complexType>

- <s:sequence>

  <s:element minOccurs="0" maxOccurs="1" name="TocnoVrijemeResult" type="s:string" />

  </s:sequence>

  </s:complexType>

  </s:element>

  </s:schema>

  </types>

- <message name="TocnoVrijemeSoapIn">

  <part name="parameters" element="s0:TocnoVrijeme" />

  </message>

- <message name="TocnoVrijemeSoapOut">

  <part name="parameters" element="s0:TocnoVrijemeResponse" />

  </message>

- <portType name="Za_x0020_prezentaciju_x0020_Web_x0020_ServisSoap">

- <operation name="TocnoVrijeme">

  <input message="s0:TocnoVrijemeSoapIn" />

  <output message="s0:TocnoVrijemeSoapOut" />

  </operation>

  </portType>

- <binding name="Za_x0020_prezentaciju_x0020_Web_x0020_ServisSoap"

type="s0:Za_x0020_prezentaciju_x0020_Web_x0020_ServisSoap">

  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />

- <operation name="TocnoVrijeme">

  <soap:operation soapAction="ZaPrezentaciju/TocnoVrijeme" style="document" />

- <input>

  <soap:body use="literal" />

  </input>

- <output>

  <soap:body use="literal" />

  </output>

  </operation>

  </binding>

- <service name="Za_x0020_prezentaciju_x0020_Web_x0020_Servis">

  <documentation>Koliko je sati?</documentation>

- <port name="Za_x0020_prezentaciju_x0020_Web_x0020_ServisSoap"

binding="s0:Za_x0020_prezentaciju_x0020_Web_x0020_ServisSoap">

  <soap:address location="http://localhost/WebServis/zaprezentaciju.asmx" />

  </port>

  </service>

  </definitions>

©MARIN JARAM 2003/2004