我想用c#實現一個web服務。我有興趣實現服務器而不是消費者。 Web服務必須由一個獨立的軟件運行,因爲我沒有像IIS這樣的網絡服務器來部署它。我知道我可以帶一個wsdl文件,使用gsoap爲它生成C代碼,我在服務器端實現例程,並構建鏈接libgsoap的獨立程序。沒有網絡服務器的獨立c#webservice
現在我想用c#和.net平臺來做同樣的事情。
我用來研究它的wsdl文件與gsoap一樣,你可以找到它here。
下一步是下載它並運行wsdl -server cal.wsdl
以獲得calc.cs
。
在這一點上,我卡住了,因爲我無法找到關於如何進行的文檔。
如何實現擴展抽象類calc的程序?我通過運行wsdl獲得的啓動一個小型web服務器來執行所需的功能?你能指點我一些很好的文檔嗎?
新增
當我運行wsdl -server cal.wsdl
我得到這個代碼
/// <remarks/>
/// <remarks>
///gSOAP 2.7.9k generated service definition
///</remarks>
[System.Web.Services.WebServiceAttribute(Namespace="http://websrv.cs.fsu.edu/~engelen/calc.wsdl")]
[System.Web.Services.WebServiceBinding(Name="calc", Namespace="http://websrv.cs.fsu.edu/~engelen/calc.wsdl")]
public abstract partial class calc : System.Web.Services.WebService {
/// <remarks>
///Service definition of function ns__add
///</remarks>
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:calc", ResponseNamespace="urn:calc")]
[return: System.Xml.Serialization.SoapElement("result")]
public abstract double add(double a, double b);
/// <remarks>
///Service definition of function ns__sub
///</remarks>
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:calc", ResponseNamespace="urn:calc")]
[return: System.Xml.Serialization.SoapElement("result")]
public abstract double sub(double a, double b);
/// <remarks>
///Service definition of function ns__mul
///</remarks>
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:calc", ResponseNamespace="urn:calc")]
[return: System.Xml.Serialization.SoapElement("result")]
public abstract double mul(double a, double b);
/// <remarks>
///Service definition of function ns__div
///</remarks>
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:calc", ResponseNamespace="urn:calc")]
[return: System.Xml.Serialization.SoapElement("result")]
public abstract double div(double a, double b);
/// <remarks>
///Service definition of function ns__pow
///</remarks>
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:calc", ResponseNamespace="urn:calc")]
[return: System.Xml.Serialization.SoapElement("result")]
public abstract double pow(double a, double b);
}
這是一個抽象類,因爲所有在服務器端的方法沒有實現。因此,我期待着,就像我通常用gsoap做的那樣,我將不得不擴展這個類並重寫抽象方法,這很容易。
問題是,之後我不知道如何編寫一個程序,該程序採用繼承的類並啓動Web服務器並在網絡上公開Web服務。
聽起來就像你試圖從wsdl生成web服務實現。這不可能。一個wsdl文件不包含邏輯,它只告訴客戶端它需要與服務器進行通信的方法和類型。 – i3arnon
是的,這就是爲什麼我在Linux/Unix中編寫代碼時使用gsoap生成C代碼,編譯前我還實現了服務器的例程,以便它知道在調用web服務時必須執行的操作。 –
你問如何編寫代碼和C#並編譯它? – i3arnon