<% @ Class = "FinReportWebService.FinReportService" %>
using System;
using System.Web.Services;
namespace FinReportWebService {
public class FinReportService {
[ WebMethod ]
public int [] GetReportIdArray ( DateTime dateBegin, DateTime dateEnd) {
int [] array = new int [] {357, 358, 360, 361};
return array;
}
[ WebMethod ]
public FinReport GetReport ( int reportID) {
FinReport finReport = new FinReport () {
ReportID = reportID,
Date = new DateTime (2015, 03, 15),
Info = "Some info"
};
return finReport;
}
}
public class FinReport {
public int ReportID { get ; set ; }
public DateTime Date { get ; set ; }
public string Info { get ; set ; }
}
}
<% @ WebService Language = "C #" CodeBehind = "ExchangeRate.asmx.cs" Class = "FinReportWebService.ExchangeRate" %>
using System;
using System.Web.Services;
using System.Xml.Serialization;
namespace FinReportWebService {
[ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]
[ WebService (Description = " Fin . Reports " , Namespace = XmlNS)]
public class FinReportService : WebService {
public const string XmlNS = "http://asmx.habrahabr.ru/" ;
[ WebMethod (Description = "Get a list of report IDs by period" )]
public GetReportIdArrayResult GetReportIdArray ( GetReportIdArrayArg arg) {
return new GetReportIdArrayResult () {
ReportIdArray = new int [] {357, 358, 360, 361}
};
}
[ WebMethod (Description = " Getting report by id " )]
public GetReportResult GetReport ( GetReportArg arg) {
return new GetReportResult () {
Report = new FinReport {
ReportID = arg.ReportID,
Date = new DateTime (2015, 03, 15),
Info = getReportInfo (arg.ReportID)
}
};
}
private string getReportInfo ( int reportID) {
return "ReportID =" + reportID;
}
}
// [Serializable]
// [XmlType (Namespace = FinReportService.XmlNS)]
public class FinReport {
public int ReportID { get ; set ; }
public DateTime Date { get ; set ; }
public string Info { get ; set ; }
}
public class GetReportIdArrayArg {
public DateTime DateBegin { get ; set ; }
public DateTime DateEnd { get ; set ; }
}
public class GetReportIdArrayResult {
public int [] ReportIdArray { get ; set ; }
}
public class GetReportArg {
public int ReportID { get ; set ; }
}
public class GetReportResult {
public FinReport Report { get ; set ; }
}
}
wsdl http://192.168.1.101:8080/SomeDir/SomeService?wsdl
wsdl HabraService.wsdl
wsdl /n:FinReportWebServiceClient.ProxyClass http: // localhost: 3500 / FinReport.asmx? wsdl
pause
public static FinReportService GetFinReportService () {
var service = new FinReportService ();
service.Url = "http: // localhost: 3500 / FinReport.asmx" ;
service.Timeout = 100 * 1000;
return service;
}
private void webMethodTest_GetReportIdArray () {
var service = GetFinReportService ();
var arg = new GetReportIdArrayArg ();
arg.DateBegin = new DateTime (2015, 03, 01);
arg.DateEnd = new DateTime (2015, 03, 02);
var result = service.GetReportIdArray (arg);
MessageBox .Show ( "result.ReportIdArray.Length =" + result.ReportIdArray.Length);
}
private void webMethodTest_GetReport () {
var service = GetFinReportService ();
var arg = new GetReportArg ();
arg.ReportID = 45;
var result = service.GetReport (arg);
MessageBox .Show (result.Report.Info);
}
wsdl / n: MyNamespace HabraService.wsdl Data.xsd Common.xsd Schema.xsd
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< wsdl: definitions xmlns: tm = " http://microsoft.com/wsdl/mime/textMatching/ " xmlns: soapenc = " http://schemas.xmlsoap.org/soap/encoding/ " xmlns: mime = " http://schemas.xmlsoap.org/wsdl/mime/ " xmlns: tns = " http://asmx.habrahabr.ru/ " xmlns: soap = " http://schemas.xmlsoap.org/wsdl/soap/ " xmlns: s = " http://www.w3.org/2001/XMLSchema " xmlns: soap12 = " http://schemas.xmlsoap.org/wsdl/soap12/ " xmlns: http = " http://schemas.xmlsoap.org/wsdl/http/ " targetNamespace = " http://asmx.habrahabr.ru/ " xmlns: wsdl = " http://schemas.xmlsoap.org/wsdl/ " >
< wsdl: documentation xmlns: wsdl = " http://schemas.xmlsoap.org/wsdl/ " > Fin. reports </ wsdl: documentation >
< wsdl: types >
< s: schema elementFormDefault = " qualified " targetNamespace = " http://asmx.habrahabr.ru/ " >
< s: element name = " GetReportIdArray " >
< s: complexType >
< s: sequence >
< s: element minOccurs = " 0 " maxOccurs = " 1 " name = " arg " type = " tns: GetReportIdArrayArg " />
</ s: sequence >
</ s: complexType >
</ s: element >
< s: complexType name = " GetReportIdArrayArg " >
< s: sequence >
< s: element minOccurs = " 1 " maxOccurs = " 1 " name = " DateBegin " type = " s: dateTime " />
< s: element minOccurs = " 1 " maxOccurs = " 1 " name = " DateEnd " type = " s: dateTime " />
</ s: sequence >
</ s: complexType >
< s: element name = " GetReportIdArrayResponse " >
< s: complexType >
< s: sequence >
< s: element minOccurs = " 0 " maxOccurs = " 1 " name = " GetReportIdArrayResult " type = " tns: GetReportIdArrayResult " />
</ s: sequence >
</ s: complexType >
</ s: element >
< s: complexType name = " GetReportIdArrayResult " >
< s: sequence >
< s: element minOccurs = " 0 " maxOccurs = " 1 " name = " ReportIdArray " type = " tns: ArrayOfInt " />
</ s: sequence >
</ s: complexType >
< s: complexType name = " ArrayOfInt " >
< s: sequence >
< s: element minOccurs = " 0 " maxOccurs = " unbounded " name = " int " type = " s: int " />
</ s: sequence >
</ s: complexType >
< s: element name = " GetReport " >
< s: complexType >
< s: sequence >
< s: element minOccurs = " 0 " maxOccurs = " 1 " name = " arg " type = " tns: GetReportArg " />
</ s: sequence >
</ s: complexType >
</ s: element >
< s: complexType name = " GetReportArg " >
< s: sequence >
< s: element minOccurs = " 1 " maxOccurs = " 1 " name = " ReportID " type = " s: int " />
</ s: sequence >
</ s: complexType >
< s: element name = " GetReportResponse " >
< s: complexType >
< s: sequence >
< s: element minOccurs = " 0 " maxOccurs = " 1 " name = " GetReportResult " type = " tns: GetReportResult " />
</ s: sequence >
</ s: complexType >
</ s: element >
< s: complexType name = " GetReportResult " >
< s: sequence >
< s: element minOccurs = " 0 " maxOccurs = " 1 " name = " Report " type = " tns: FinReport " />
</ s: sequence >
</ s: complexType >
< s: complexType name = " FinReport " >
< s: sequence >
< s: element minOccurs = " 1 " maxOccurs = " 1 " name = " ReportID " type = " s: int " />
< s: element minOccurs = " 1 " maxOccurs = " 1 " name = " Date " type = " s: dateTime " />
< s: element minOccurs = " 0 " maxOccurs = " 1 " name = " Info " type = " s: string " />
</ s: sequence >
</ s: complexType >
</ s: schema >
</ wsdl: types >
< wsdl: message name = " GetReportIdArraySoapIn " >
< wsdl: part name = " parameters " element = " tns: GetReportIdArray " />
</ wsdl: message >
< wsdl: message name = " GetReportIdArraySoapOut " >
< wsdl: part name = " parameters " element = " tns: GetReportIdArrayResponse " />
</ wsdl: message >
< wsdl: message name = " GetReportSoapIn " >
< wsdl: part name = " parameters " element = " tns: GetReport " />
</ wsdl: message >
< wsdl: message name = " GetReportSoapOut " >
< wsdl: part name = " parameters " element = " tns: GetReportResponse " />
</ wsdl: message >
< wsdl: portType name = " FinReportServiceSoap " >
< wsdl: operation name = " GetReportIdArray " >
< wsdl: documentation xmlns: wsdl = " http://schemas.xmlsoap.org/wsdl/ " > Getting a list of report IDs by period </ wsdl: documentation >
< wsdl: input message = " tns: GetReportIdArraySoapIn " />
< wsdl: output message = " tns: GetReportIdArraySoapOut " />
</ wsdl: operation >
< wsdl: operation name = " GetReport " >
< wsdl: documentation xmlns: wsdl = " http://schemas.xmlsoap.org/wsdl/ " > Getting the report by ID </ wsdl: documentation >
< wsdl: input message = " tns: GetReportSoapIn " />
< wsdl: output message = " tns: GetReportSoapOut " />
</ wsdl: operation >
</ wsdl: portType >
< wsdl: binding name = " FinReportServiceSoap " type = " tns: FinReportServiceSoap " >
< soap: binding transport = " http://schemas.xmlsoap.org/soap/http " />
< wsdl: operation name = " GetReportIdArray " >
< soap: operation soapAction = " http://asmx.habrahabr.ru/GetReportIdArray " style = " document " />
< wsdl: input >
< soap: body use = " literal " />
</ wsdl: input >
< wsdl: output >
< soap: body use = " literal " />
</ wsdl: output >
</ wsdl: operation >
< wsdl: operation name = " GetReport " >
< soap: operation soapAction = " http://asmx.habrahabr.ru/GetReport " style = " document " />
< wsdl: input >
< soap: body use = " literal " />
</ wsdl: input >
< wsdl: output >
< soap: body use = " literal " />
</ wsdl: output >
</ wsdl: operation >
</ wsdl: binding >
< wsdl: binding name = " FinReportServiceSoap12 " type = " tns: FinReportServiceSoap " >
< soap12: binding transport = " http://schemas.xmlsoap.org/soap/http " />
< wsdl: operation name = " GetReportIdArray " >
< soap12: operation soapAction = " http://asmx.habrahabr.ru/GetReportIdArray " style = " document " />
< wsdl: input >
< soap12: body use = " literal " />
</ wsdl: input >
< wsdl: output >
< soap12: body use = " literal " />
</ wsdl: output >
</ wsdl: operation >
< wsdl: operation name = " GetReport " >
< soap12: operation soapAction = " http://asmx.habrahabr.ru/GetReport " style = " document " />
< wsdl: input >
< soap12: body use = " literal " />
</ wsdl: input >
< wsdl: output >
< soap12: body use = " literal " />
</ wsdl: output >
</ wsdl: operation >
</ wsdl: binding >
< wsdl: service name = " FinReportService " >
< wsdl: documentation xmlns: wsdl = " http://schemas.xmlsoap.org/wsdl/ " > Fin. reports </ wsdl: documentation >
< wsdl: port name = " FinReportServiceSoap " binding = " tns: FinReportServiceSoap " >
< soap: address location = " http: // localhost: 3500 / FinReport.asmx " />
</ wsdl: port >
< wsdl: port name = " FinReportServiceSoap12 " binding = " tns: FinReportServiceSoap12 " >
< soap12: address location = " http: // localhost: 3500 / FinReport.asmx " />
</ wsdl: port >
</ wsdl: service >
</ wsdl: definitions >
wsdl / server /n:FinReportWebServiceByWsdl.ServerClass FinReport.wsdl
pause
using System;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using FinReportWebServiceByWsdl.ServerClass;
namespace FinReportWebServiceByWsdl {
[ WebService (Namespace = "http://asmx.habrahabr.ru/" )]
[ WebServiceBinding (Name = "FinReportServiceSoap" , Namespace = "http://asmx.habrahabr.ru/" )]
public class FinReportService : WebService {
[ WebMethod ]
[ SoapDocumentMethod ( "http://asmx.habrahabr.ru/GetReportIdArray" ,
RequestNamespace = "http://asmx.habrahabr.ru/" ,
ResponseNamespace = "http://asmx.habrahabr.ru/" ,
Use = SoapBindingUse .Literal,
ParameterStyle = SoapParameterStyle .Wrapped)]
public GetReportIdArrayResult GetReportIdArray ( GetReportIdArrayArg arg) {
return new GetReportIdArrayResult ();
}
[ WebMethod ]
[ SoapDocumentMethod ( "http://asmx.habrahabr.ru/GetReport" ,
RequestNamespace = "http://asmx.habrahabr.ru/" ,
ResponseNamespace = "http://asmx.habrahabr.ru/" ,
Use = SoapBindingUse .Literal,
ParameterStyle = SoapParameterStyle .Wrapped)]
public GetReportResult GetReport ( GetReportArg arg) {
return new GetReportResult () {
Report = new FinReport {
ReportID = arg.ReportID,
Date = new DateTime (2015, 03, 15),
Info = "ByWSDL"
}
};
}
}
}
<% @ Class = "FinReportWebServiceByWsdl.FinReportService" %>
<% @ Class = "FinReportWebService.FinReportService" %>
using System;
using System.Text;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;
using Newtonsoft.Json;
namespace FinReportWebService {
[ ScriptService ]
[ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]
[ WebService (Description = " Fin . Reports " , Namespace = "http://asmx.habrahabr.ru/" )]
public class FinReportService : WebService {
[ ScriptMethod (ResponseFormat = ResponseFormat .Json)]
[ WebMethod ]
public GetReportResult Method_1_POST_Objects ( GetReportArg arg) {
return getFinReportResult (arg.ReportID, "Method_1_POST_Objects" );
}
[ ScriptMethod (ResponseFormat = ResponseFormat .Json, UseHttpGet = true )]
[ WebMethod ]
public string Method_2_GET ( int id) {
var result = getFinReportResult (id, "Method_2_GET" );
string text = JsonConvert .SerializeObject (result);
return text;
}
[ ScriptMethod (ResponseFormat = ResponseFormat .Json)]
[ WebMethod ]
public string Method_3_POST ( int id) {
var result = getFinReportResult (id, "Method_3_POST" );
JavaScriptSerializer js = new JavaScriptSerializer ();
return js.Serialize (result);
}
[ ScriptMethod (ResponseFormat = ResponseFormat .Json)]
[ WebMethod ]
public string Method_4_POST_ComplexArg ( string json) {
var arg = JsonConvert .DeserializeObject < GetReportArg > (json);
var result = getFinReportResult (arg.ReportID, arg.Token + " Received ." );
return JsonConvert .SerializeObject (result);
}
[ ScriptMethod (ResponseFormat = ResponseFormat .Json)]
[ WebMethod ]
public DateTime Method_5_TransformDate ( DateTime dateTime) {
Return dateTime.AddYears (-3) .AddDays (-5) .AddHours (-2) .AddMinutes (6);
}
[ ScriptMethod (ResponseFormat = ResponseFormat .Json)]
[ WebMethod ]
public void Method_6_POST_NonStandard ( int id) {
var result = getFinReportResult (id, "Method_6_POST_NonStandard, My text " );
string text = JsonConvert .SerializeObject (result);
byte [] data = Encoding .UTF8.GetBytes (text);
Context.Response.Clear ();
Context.Response.ContentType = "application / json; charset = utf-8" ;
Context.Response.AddHeader ( "content-length" , data.Length.ToString ());
Context.Response.BinaryWrite (data);
Context.Response.Flush ();
}
private GetReportResult getFinReportResult ( int id, string info) {
return new GetReportResult () {
Report = new FinReport () {
ReportID = id,
Info = info,
Date = new DateTime (2015, 03, 15),
}
};
}
}
public class FinReport {
public DateTime Date { get ; set ; }
public string Info { get ; set ; }
public int ReportID { get ; set ; }
}
public class GetReportArg {
public int ReportID { get ; set ; }
public string Token { get ; set ; }
}
public class GetReportResult {
public FinReport Report { get ; set ; }
}
}
<! doctype html >
< html >
< head >
< meta charset = utf-8>
< script src = "// ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></ script >
< script >
$ (document) .ready ( function () {
$ ( "# btn1" ) .click ( function () {
var arg = {arg: {ReportID: 1}};
$ .ajax ({
type: "POST" ,
contentType: "application / json; charset = utf-8" ,
url: "/FinReport.asmx/Method_1_POST_Objects" ,
data: JSON.stringify (arg),
dataType: "json" ,
success: function (data, status) {
$ ( "# div1" ) .html (data.d.Report.Info);
},
error: function (request, status, error) {alert ( "Error" ); }
});
});
$ ( "# btn2" ) .click ( function () {
$ .ajax ({
type: "GET" ,
contentType: "application / json; charset = utf-8" ,
url: "/FinReport.asmx/Method_2_GET" ,
data: {id: 2},
dataType: "json" ,
success: function (data, status) {
$ ( "# div2" ) .html (JSON.parse (data.d) .Report.Info);
},
error: function (request, status, error) {alert ( "Error" ); }
});
});
$ ( "# btn3" ) .click ( function () {
$ .ajax ({
type: "POST" ,
contentType: "application / json; charset = utf-8" ,
url: "/FinReport.asmx/Method_3_POST" ,
data: '{"id": 3}' ,
dataType: "json" ,
success: function (data, status) {
$ ( "# div3" ) .html (JSON.parse (data.d) .Report.Info);
},
error: function (request, status, error) {alert ( "Error" ); }
});
});
$ ( "# btn4" ) .click ( function () {
var arg = {ReportID: 4, Token: " Token method 4. " };
var argObj = {json: JSON.stringify (arg)};
$ .ajax ({
type: "POST" ,
contentType: "application / json; charset = utf-8" ,
url: "/FinReport.asmx/Method_4_POST_ComplexArg" ,
data: JSON.stringify (argObj),
dataType: "json" ,
success: function (data, status) {
$ ( "# div4" ) .html (JSON.parse (data.d) .Report.Info);
},
error: function (request, status, error) {alert ( "Error" ); }
});
});
$ ( "# btn5" ) .click ( function () {
var now = new Date ();
var arg = {dateTime: now};
$ .ajax ({
type: "POST" ,
contentType: "application / json; charset = utf-8" ,
url: "/FinReport.asmx/Method_5_TransformDate" ,
data: JSON.stringify (arg),
dataType: "json" ,
success: function (data, status) {
var date = new Date (parseInt (data.d.replace ( "/ Date (" , "" ) .replace ( ") /" , "" ), 10));
$ ( "# div5" ) .html (date.toString ());
},
error: function (request, status, error) {alert ( "Error" ); }
});
});
$ ( "# btn6" ) .click ( function () {
$ .ajax ({
type: "POST" ,
contentType: "application / json; charset = utf-8" ,
url: "/FinReport.asmx/Method_6_POST_NonStandard" ,
data: '{"id": 6}' ,
dataType: "json" ,
success: function (data, status) {
$ ( "# div6" ) .html (data.Report.Info);
},
error: function (request, status, error) {alert ( "Error" ); }
});
});
});
</ script >
</ head >
< body >
< div id = "div1"> Div 1 </ div >
< div id = "div2"> Div 2 </ div >
< div id = "div3"> Div 3 </ div >
< div id = "div4"> Div 4 </ div >
< div id = "div5"> Div 5 </ div >
< div id = "div6"> Div 6 </ div >
<Br />
< button id = "btn1"> Method 1 </ button >
<Br />
< button id = "btn2"> Method 2 </ button >
<Br />
< button id = "btn3"> Method 3 </ button >
<Br />
< button id = "btn4"> Method 4 </ button >
<Br />
< button id = "btn5"> Method 5 </ button >
<Br />
< button id = "btn6"> Method 6 </ button >
</ body >
</ html >
{
" arg ": {
"ReportID": 1
}
}
{, . JSON- - «d». "__type": «FinReportWebService.GetReportResult». "/Date(1426356000000)/" . , 5 , , , .
" d ": {
"__type": "FinReportWebService.GetReportResult" ,
"Report": {
"ReportID": 1 ,
"Date": "/Date(1426356000000)/" ,
"Info": "Method_1_POST_Objects"
}
}
}
{, JSON.parse(data.d), :
" d": "{\"Report\":{\"ReportID\":2,\"Date\":\"2015-03-15T00:00:00\",\"Info\":\"Method_2_GET\"}}"
}
{, Json.NET . contentType: «application/json; charset=utf-8», , GET. CSRF. URL . GET .
" Report": {
"ReportID": 2 ,
"Date": "2015-03-15T00:00:00" ,
"Info": "Method_2_GET"
}
}
{:
" id ": 3
}
{
" d": "{\"Report\":{\"ReportID\":3,\"Date\":\"\\/Date(1426356000000)\\/\",\"Info\":\"Method_3_POST\"}}"
}
{.
"json": "{\"ReportID\":4,\"Token\":\" 4\"}"
}
var date = new Date(parseInt(data.d.replace( "/Date(" , "" ).replace( ")/" , "" ), 10));
{
" dateTime": "2015-03-25T05:49:13.604Z"
}
{, «d». GET. , - «application/json;».
" Report": {
"Date": "2015-03-15T00:00:00" ,
"Info": "Method_6_GET_NonStandard, " ,
"ReportID": 6
}
}
<? xml version = " 1.0 " ?>
< configuration >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " />
</ system.web >
< system.web.extensions >
< scripting >
< webServices >
< jsonSerialization maxJsonLength = " 1073741824 " />
</ webServices >
</ scripting >
</ system.web.extensions >
</ configuration >
private string getReportInfo() {
var request = this .Context.Request;
// var request = HttpContext.Current.Request;
StringBuilder sb = new StringBuilder ();
sb.Append( "IP = " ).AppendLine(request.UserHostAddress);
sb.Append( "URL = " ).AppendLine(request.Url.OriginalString);
sb.Append( "Header 'Connection' = " ).AppendLine(request.Headers[ "Connection" ]);
DateTime dnsDate = DateTime .Now;
TimeSpan dnsSpan;
try {
// throw new Exception(" .");
var entry = Dns.GetHostEntry(request.UserHostAddress);
dnsSpan = DateTime .Now.Subtract(dnsDate);
sb.Append( "HostName = " ).AppendLine(entry.HostName);
} catch ( Exception ex) {
dnsSpan = DateTime .Now.Subtract(dnsDate);
sb.AppendLine(ex.Message);
}
sb.Append( "dnsSpan = " ).AppendLine(dnsSpan.ToString());
return sb.ToString();
}
private string getReportInfo( int reportID) {MyFiles Cars.txt Build Action: None / Copy always - :
string dirRoot = HttpContext .Current.Server.MapPath( "~" );
StringBuilder sb = new StringBuilder ();
sb.AppendLine( "dirRoot = " + dirRoot);
string fileCars = HttpContext .Current.Server.MapPath( "~/bin/MyFiles/Cars.txt" );
sb.AppendLine( "fileCars = " + fileCars);
try {
sb.AppendLine( "Line 1 = " + File .ReadAllLines(fileCars)[0]);
File .AppendAllText(fileCars, Environment .NewLine + DateTime .Now + " ReportID = " + reportID);
} catch ( Exception ex) {
sb.AppendLine(ex.Message);
}
string dirFiles = Path .Combine(( new DirectoryInfo (dirRoot)).Parent.FullName, "FinReportWebService_Files" );
sb.AppendLine( "dirFiles = " + dirFiles);
try {
Directory .CreateDirectory(dirFiles);
string newFile = Path .Combine(dirFiles, Guid .NewGuid() + ".txt" );
File .WriteAllText(newFile, "ReportID = " + reportID);
sb.AppendLine(newFile);
} catch ( Exception ex) {
sb.AppendLine(ex.Message);
}
return sb.ToString();
}
dirRoot = C:\CommonFolder\publish_FinReport. 19. IIS.
fileCars = C:\CommonFolder\publish_FinReport\bin\MyFiles\Cars.txt
Line 1 = Audi
Access to the path 'C:\CommonFolder\publish_FinReport\bin\MyFiles\Cars.txt' is denied.
dirFiles = C:\CommonFolder\FinReportWebService_Files
Access to the path 'C:\CommonFolder\FinReportWebService_Files' is denied.
<? xml version = " 1.0 " ?>compilation.
< configuration >
< appSettings >
< add key = " ReportType " value = " 8 " />
< add key = " ReportSubject " value = " " />
</ appSettings >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " />
</ system.web >
</ configuration >
using System;
using System.Collections.Generic;
using System.Configuration;
namespace FinReportWebService {
internal static class WebConfig {
public static int ReportType { get { return getStructureValue < int > ( "ReportType" ); }}
public static string ReportSubject { get { return getTextValue ( "ReportSubject" ); }}
public static string DbLogin { get { return getTextValue ( "DbLogin" , true ); }}
public static string DbPass { get { return getTextValue ( "DbPass" , true ); }}
// =============================================== ==========
private static string getTextValue ( string name, bool getDefaultOnNotFound = false ) {
string value = ConfigurationManager .AppSettings [name];
if (value == null &&! getDefaultOnNotFound) {
throw new KeyNotFoundException ( " In the web.config file is not found setting "" + name + "" " );
}
return value;
}
private static T getStructureValue <T> ( string name, bool getDefaultOnNotFound = false ) where T: struct {
string textValue = getTextValue (name, getDefaultOnNotFound);
if (textValue == null ) {
return default (T);
}
try {
T value = (T) Convert .ChangeType (textValue, typeof (T));
return value;
} catch ( Exception ex) {
string message = "In the web.config file, the setting '{0}' with the value '{1}' could not be parsed as '{2}'" ;
message = string .Format (message, name, textValue, typeof (T) .Name);
throw new InvalidCastException (message, ex);
}
}
}
}
private static string getReportInfo ( int reportID) {Now you can test the read configuration.
StringBuilder sb = new StringBuilder ();
try {
sb.Append ( "ReportType =" ) .AppendLine ( WebConfig .ReportType.ToString ());
sb.Append ( "ReportSubject =" ) .AppendLine ( WebConfig .ReportSubject);
sb.Append ( "DbLogin =" ) .AppendLine ( WebConfig .DbLogin);
sb.Append ( "DbPass =" ) .AppendLine ( WebConfig .DbPass);
} catch ( Exception ex) {
sb.AppendLine (ex.Message);
}
return sb.ToString ();
}
<? xml version = " 1.0 " ?>And change web.config itself to:
< appSettings >
< add key = " ReportSubject " value = " Small business " />
< add key = " DbLogin " value = " reader " />
< add key = " DbPass " value = " uYE4_wn7xc5Sp " />
</ appSettings >
<? xml version = " 1.0 " ?>
< configuration >
< appSettings file = " web_alpha.config " >
< add key = " ReportType " value = " 8 " />
< add key = " ReportSubject " value = " Medium business " />
</ appSettings >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " />
</ system.web >
</ configuration >
<? xml version = " 1.0 " ?>Change the web.config accordingly to:
< appSettings >
< add key = " ReportSubject " value = " Large business " />
< add key = " DbLogin " value = " admin " />
< add key = " DbPass " value = " guXu4awewr $ w " />
</ appSettings >
<? xml version = " 1.0 " ?>
< configuration >
< appSettings file = " .. /web_beta.config " >
< add key = " ReportType " value = " 8 " />
< add key = " ReportSubject " value = " Medium business " />
</ appSettings >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " />
</ system.web >
</ configuration >
<? xml version = " 1.0 " ?>And create the web_gamma.config file:
< configuration >
< appSettings configSource = " web_gamma.config " />
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " />
</ system.web >
</ configuration >
<? xml version = " 1.0 " ?>This approach is less flexible, as it has a number of major differences from the previous one:
< appSettings >
< add key = " ReportType " value = " 9 " />
< add key = " ReportSubject " value = " Noncommercial " />
< add key = " DbLogin " value = " writer " />
< add key = " DbPass " value = " hQ5zGPPSrkqqfsb " />
</ appSettings >
<? xml version = " 1.0 " ?>
< configuration xmlns : xdt = " http : // schemas . microsoft . com / XML - Document - Transform " >
< appSettings >
< add key = " ReportSubject " value = " debag " xdt: Transform = " Replace " xdt: Locator = " Match (key) " />
</ appSettings >
</ configuration >
<? xml version = " 1.0 " ?>
< configuration xmlns: xdt = " http://schemas.microsoft.com/XML-Document-Transform " >
< system.web >
< compilation xdt: Transform = " RemoveAttributes (debug) " />
</ system.web >
</ configuration >
<? xml version = " 1.0 " ?>
< configuration >
< appSettings >
< add key = " ReportType " value = " 8 " />
< add key = " ReportSubject " value = " Medium business " />
</ appSettings >
< system.web >
<! - 100 mb and 30 minutes ( valid only with compilation.debug = false) ->
< httpRuntime maxRequestLength = " 102400 " executionTimeout = " 1800 " />
< compilation targetFramework = " 4.0 " >
</ compilation >
</ system.web >
< system.webServer >
< security >
< requestFiltering >
<! - 100 mb ->
< requestLimits maxAllowedContentLength = " 104857600 " />
</ requestFiltering >
</ security >
</ system.webServer >
</ configuration >
using System;Also in the project should be the following 3 asmx files:
using System.Configuration;
using System.Web.Services;
namespace FinReportWebService {
[ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]
[ WebService (Description = " Fin . Reports v.2" , Namespace = XmlNS)]
public class FinReportService_v2 : FinReportService {
public FinReportService_v2 (): base (2) {
}
}
[ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]
[ WebService (Description = "CHECK: Fin . Reports " , Namespace = FinReportService .XmlNS)]
public class FinReportService_Check {
private FinReportService _service;
public FinReportService_Check () {
_service = new FinReportService ();
}
[ WebMethod (Description = " Enter identifier report . " )]
public GetReportResult GetReport ( int reportID) {
GetReportArg arg = new GetReportArg ();
arg.ReportID = reportID;
return _service.GetReport (arg);
}
[ WebMethod (Description = " Period : January 2015. " )]
public GetReportIdArrayResult GetReportIdArray () {
GetReportIdArrayArg arg = new GetReportIdArrayArg ();
arg.DateBegin = new DateTime (2015, 01, 01);
arg.DateEnd = new DateTime (2015, 02, 01);
return _service.GetReportIdArray (arg);
}
}
[ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]
[ WebService (Description = " Fin . Reports " , Namespace = XmlNS)]
public class FinReportService : WebService {
public const string XmlNS = "http://asmx.habrahabr.ru/" ;
private int _version;
public FinReportService () {
_version = 1;
}
public FinReportService ( int version) {
_version = version;
}
[ WebMethod (Description = " Getting report ID list by period " )]
public GetReportIdArrayResult GetReportIdArray ( GetReportIdArrayArg arg) {
return new GetReportIdArrayResult () {
ReportIdArray = new int [] {357, 358, 360, 361}
};
}
[ WebMethod (Description = " Getting report by id " )]
public GetReportResult GetReport ( GetReportArg arg) {
return new GetReportResult () {
Report = new FinReport {
ReportID = arg.ReportID,
Date = new DateTime (2015, 03, 15),
Info = "Phone:" + ConfigurationManager .AppSettings [ "phone" ] + "Version:" + _version
}
};
}
}
public class FinReport {
public int ReportID { get ; set ; }
public DateTime Date { get ; set ; }
public string Info { get ; set ; }
}
public class GetReportIdArrayArg {
public DateTime DateBegin { get ; set ; }
public DateTime DateEnd { get ; set ; }
}
public class GetReportIdArrayResult {
public int [] ReportIdArray { get ; set ; }
}
public class GetReportArg {
public int ReportID { get ; set ; }
}
public class GetReportResult {
public FinReport Report { get ; set ; }
}
}
<% @ Class = "FinReportWebService.FinReportService" %>FinReport_v2.asmx - new:
<% @ Class = "FinReportWebService.FinReportService_v2" %>FinReport_CHECK.asmx - new:
<% @ Class = "FinReportWebService.FinReportService_Check" %>And change web.config to:
<? xml version = " 1.0 " ?>As you can see, two new asmx files refer to two new classes. First I will explain the purpose of the FinReportService_v2 class. Its only functional difference from the base class is that its default constructor initializes the int _version field with a value of 2, not 1. Thus, the web service has a clone that has exactly the same contract, but there are differences in processing requests. For example, this clone may be intended for testing or actually represent a new version.
< configuration >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " />
</ system.web >
< appSettings >
< add key = " phone " value = " nokia " />
</ appSettings >
< location path = " FinReport.asmx " >
< appSettings >
< add key = " phone " value = " samsung " />
</ appSettings >
</ location >
< location path = " FinReport_v2.asmx " >
< appSettings >
< add key = " phone " value = " htc " />
</ appSettings >
</ location >
< location path = " FinReport_CHECK.asmx " >
< appSettings >
< add key = " phone " value = " apple " />
</ appSettings >
< system.web >
< webServices >
< protocols >
< clear />
< add name = " Documentation " />
< add name = " HttpPostLocalhost " />
</ protocols >
</ webServices >
</ system.web >
</ location >
</ configuration >
<! doctype html >And specify in web.config
< html >
< head >
< meta charset = utf-8>
< title > Welcome </ title >
</ head >
< body >
< p > Welcome! < / p >
</ body >
</ html >
<? xml version = " 1.0 " ?>
< configuration >
< system.web >
< webServices >
< wsdlHelpGenerator href = " FinReportPage.aspx " />
</ webServices >
< compilation debug = " true " targetFramework = " 4.0 " />
</ system.web >
</ configuration >
<? xml version = " 1.0 " ?>I will note that when launched from Visual Studio, FinReportClone.habr will not work, for this you need to make a publication in IIS. By the way, using this technique, you can replace the ASMX web service with a WCF web service while preserving the original URL.
< configuration >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " >
< buildProviders >
< remove extension = " .habr " />
< add extension = " .habr " type = " System.Web.Compilation.WebServiceBuildProvider " />
</ buildProviders >
</ compilation >
</ system.web >
< system.webServer >
< handlers >
< add name = " HabraHandler " verb = " * " path = " * .habr " type = " System.Web.Services.Protocols.WebServiceHandlerFactory " />
</ handlers >
</ system.webServer >
</ configuration >
< system.web >This is the standard way to hide web service information. In fact, it simply prohibits GET requests. Attempting to open the address in the browser will result in an exception, while POST requests for web methods work as usual. The uncritical minus of this method is what the browser says about the error.
< webServices >
< protocols >
< remove name = " Documentation " />
</ protocols >
</ webServices >
</ system . web >
using System.Web;And change the web.config:
namespace FinReportWebService {
public class FinReportGetHandler : IHttpHandler {
public void ProcessRequest ( HttpContext context) {
string response =
@ "<! doctype html>
<html>
<head>
<meta charset = utf-8>
</ head>
<body>
<p> {0} </ p>
</ body>
</ html> " ;
bool wsdlRequested = (context.Request.QueryString.ToString (). ToLower () == "wsdl" );
if (wsdlRequested) {
response = string .Format (response, " Refer to administrator for wsdl. " );
} else {
response = string .Format (response, " Web service financial reporting . " )
}
context.Response.ContentType = "text / html; charset = utf-8" ;
context.Response.Write (response);
// string filePage = HttpContext.Current.Server.MapPath ("~ / FinReportPage.htm");
// context.Response.WriteFile (filePage);
}
public bool IsReusable {
get { return false ; }
}
}
}
<? xml version = " 1.0 " ?>
< configuration >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " >
</ compilation >
</ system.web >
< system.webServer >
< handlers >
< add name = " FinReportGetHandler " verb = " GET " path = " FinReport.asmx " type = " FinReportWebService.FinReportGetHandler " />
</ handlers >
</ system.webServer >
</ configuration >
private string getReportInfo ( int reportID) {Call the GetReport web method with throwException_1 (), which generates an unhandled divide-by-zero error. ASP.NET DevServer (or IIS) in this case will return the http code “500 Internal Server Error” instead of “200 OK” and the following content, which is formatted for convenience:
throwException_1 ();
// throwException_2 ();
// throwException_3 ();
return "ReportID =" + reportID;
}
private void throwException_1 () {
int x = 0;
x = 1 / x;
}
private void throwException_2 () {
throw new SoapException ( " Incorrect ReportID" , SoapException .ClientFaultCode, Context.Request.Url.AbsoluteUri);
}
private void throwException_3 () {
XmlDocument xmlDoc = new XmlDocument ();
XmlNode rootNode = xmlDoc. CreateNode ( XmlNodeType. Element, SoapException. DetailElementName. Name, SoapException. DetailElementName. Namespace);
XmlNode descNode = xmlDoc. CreateNode ( XmlNodeType. Element, "Description" , XmlNS);
XmlNode descTypeNode = xmlDoc. CreateNode ( XmlNodeType. Element, "Type" , XmlNS);
descTypeNode.InnerText = "DbConnection" ;
descNode.AppendChild (descTypeNode);
XmlNode descMessageNode = xmlDoc. CreateNode ( XmlNodeType. Element, "Message" , XmlNS);
descMessageNode.InnerText = " Host not found . " ;
descNode.AppendChild (descMessageNode);
XmlNode habraNode = xmlDoc. CreateNode ( XmlNodeType. Element, "HabraInfo" , XmlNS);
XmlAttribute habraNodeAttribute = xmlDoc.CreateAttribute ( "User" );
habraNodeAttribute.Value = "capslocky" ;
habraNode.Attributes.Append (habraNodeAttribute);
rootNode.AppendChild (descNode);
rootNode.AppendChild (habraNode);
XmlQualifiedName faultCode = new XmlQualifiedName ( "TempError" , XmlNS);
throw new SoapException ( " Temporary error " , faultCode, Context.Request.Url.AbsoluteUri, rootNode);
}
Unhandled exceptions always give soap: Server. In this case, the display of the exception stack depends on the customErrors setting:
<? xml version = " 1.0 " encoding = " UTF-8 " ?>
< soap: Envelope xmlns: soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns: xsd = " http://www.w3.org/2001/XMLSchema " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< soap: Fault >
< faultcode > soap: Server </ faultcode >
< faultstring > Server was unable to process request. --- & gt; Attempted to divide by zero. < / faultstring >
< detail />
</ soap: Fault >
</ soap: Body >
</ soap: Envelope >
The mode attribute has only three possible values:
<? xml version = " 1.0 " ?>
< configuration >
< system.web >
< compilation debug = " true " targetFramework = " 4.0 " />
< customErrors mode = " On " />
</ system.web >
</ configuration >
<? xml version = " 1.0 " encoding = " UTF -8 " ?>Here we changed the error code, wrote our text-explanation, and also indicated, which usually indicate the URL of the request.
< soap: Envelope xmlns: soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns: xsd = " http://www.w3.org/2001/XMLSchema " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< soap: Fault >
< faultcode > soap: Client </ faultcode >
< faultstring > Invalid ReportID </ faultstring >
< faultactor > http: //win2012/custom_folder/FinReport.asmx </ faultactor >
< detail />
</ soap: Fault >
</ soap: Body >
</ soap: Envelope >
<? xml version = " 1.0 " encoding = " UTF-8 " ?>However, it is recommended not to allow the possibility of unhandled exceptions in the web methods at all. That is, the method should always have a global try-catch, which will catch any unhandled or manually thrown exceptions, and return them to the client in a predetermined format, which can be represented both by <soap: Fault> and in the manner described below.
< soap: Envelope xmlns: soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns: xsd = " http://www.w3.org/2001/XMLSchema " xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< soap: Fault >
< faultcode xmlns: q0 = " http://asmx.habrahabr.ru/ " > q0: TempError </ faultcode >
< faultstring > Temporary Error </ faultstring >
< faultactor > http: //win2012/custom_folder/FinReport.asmx </ faultactor >
< detail >
< Description xmlns = " http://asmx.habrahabr.ru/ " >
< Type > DbConnection </ Type >
< Message > Host not found. < / Message >
</ Description >
< HabraInfo xmlns = " http://asmx.habrahabr.ru/ " User = " capslocky " />
</ detail >
</ soap: Fault >
</ soap: Body >
</ soap : Envelope >
using System;- GetReport
namespace FinReportWebService {
public class WebServiceError {
public ErrorType Type { get ; set ; }
public string Message { get ; set ; }
}
public enum ResultType {
Error,
FoundBasicData,
FoundFullData
}
public enum ErrorType {
Undefined
Dbconnection
InvalidArgument,
Forbidden
}
public class WebServiceErrorException : Exception {
public WebServiceError Error { get ; set ; }
}
public class FinReport_GetReport {
private GetReportArg _arg;
private GetReportResult _result;
public GetReportResult GetReport ( GetReportArg arg) {
_arg = arg;
initializeResultWithError ();
try {
checkArg ();
fillResult ();
} catch ( WebServiceErrorException ex) {
setResultType ( ResultType .Error);
_result. Error = ex. Error;
} catch ( Exception ex) {
setResultType ( ResultType .Error);
_result.Error.Type = ErrorType .Undefined;
_result.Error.Message = ex.GetType() + ": " + ex.Message;
}
if (_result.ResultType == ResultType .Error) {
_result.Report = null ;
} else {
_result.Error = null ;
}
return _result;
}
private void setResultType( ResultType type) {
_result.ResultType = type;
}
private void initializeResultWithError() {
_result = new GetReportResult ();
setResultType( ResultType .Error);
_result.Error = new WebServiceError ();
_result.Error.Type = ErrorType .Undefined;
_result.Error.Message = " " ;
}
private void checkArg() {
if (_arg.ReportID <= 0) {
throw new WebServiceErrorException () {
Error = new WebServiceError () {
Type = ErrorType .InvalidArgument,
Message = " : " + _arg.ReportID
}
};
}
}
private void fillResult() {
_result.Report = new FinReport ();
_result.Report.ReportID = _arg.ReportID;
_result.Report.Date = new DateTime (2015, 03, 15);
// throw new WebServiceErrorException() {
// Error = new WebServiceError() {
// Type = ErrorType.DbConnection,
// Message = " "
// }
// };
// throw new InvalidOperationException(" ");
_result.Report.Info = "Some info" ;
setResultType( ResultType .FoundFullData);
}
}
}
[ WebMethod (Description = " ID" )]GetReportResult
public GetReportResult GetReport( GetReportArg arg) {
return new FinReport_GetReport ().GetReport(arg);
}
public class GetReportResult {, ResultType , - . . . «200 OK» GetReportResult.
public ResultType ResultType { get ; set ; }
public WebServiceError Error { get ; set ; }
public FinReport Report { get ; set ; }
}
<? xml version = " 1.0 " encoding = " UTF-8 " ?>, http- -, - , soap:Fault .
< soap:Envelope xmlns:soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd = " http://www.w3.org/2001/XMLSchema " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< GetReportResponse xmlns = " http://asmx.habrahabr.ru/ " >
< GetReportResult >
< ResultType > FoundFullData </ ResultType >
< Report >
< ReportID > 45 </ ReportID >
< Date > 2015-03-15T00:00:00 </ Date >
< Info > Some info </ Info >
</ Report >
</ GetReportResult >
</ GetReportResponse >
</ soap:Body >
</ soap:Envelope >
<? xml version = " 1.0 " encoding = " UTF-8 " ?>
< soap:Envelope xmlns:soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd = " http://www.w3.org/2001/XMLSchema " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< GetReportResponse xmlns = " http://asmx.habrahabr.ru/ " >
< GetReportResult >
< ResultType > Error </ ResultType >
< Error >
< Type > DbConnection </ Type >
< Message > </ Message >
</ Error >
</ GetReportResult >
</ GetReportResponse >
</ soap:Body >
</ soap:Envelope >
<? xml version = " 1.0 " encoding = " UTF-8 " ?>
< soap:Envelope xmlns:soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd = " http://www.w3.org/2001/XMLSchema " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< GetReportResponse xmlns = " http://asmx.habrahabr.ru/ " >
< GetReportResult >
< ResultType > Error </ ResultType >
< Error >
< Type > Undefined </ Type >
< Message > System.InvalidOperationException: </ Message >
</ Error >
</ GetReportResult >
</ GetReportResponse >
</ soap:Body >
</ soap:Envelope >
<? xml version = " 1.0 " encoding = " UTF-8 " ?>
< soap:Envelope xmlns:soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd = " http://www.w3.org/2001/XMLSchema " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< GetReportResponse xmlns = " http://asmx.habrahabr.ru/ " >
< GetReportResult >
< ResultType > Error </ ResultType >
< Error >
< Type > InvalidArgument </ Type >
< Message > : -245 </ Message >
</ Error >
</ GetReportResult >
</ GetReportResponse >
</ soap:Body >
</ soap:Envelope >
using System;- -, wsdl. :
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace FinReportWebService{
[ WebServiceBinding (ConformsTo = WsiProfiles .BasicProfile1_1)]
[ WebService (Description = " . " , Namespace = XmlNS)]
public class FinReportService : WebService {
public const string XmlNS = "http://asmx.habrahabr.ru/" ;
public HabraSoapHeader HabraHeader { get ; set ; }
public ResultTimeSoapHeader ResultTimeHeader { get ; set ; }
public SoapUnknownHeader [] UnknownHeaders { get ; set ; }
[ SoapHeader ( "HabraHeader" )] //
[ SoapHeader ( "ResultTimeHeader" , Direction = SoapHeaderDirection .Out)]
[ SoapHeader ( "UnknownHeaders" )]
[ WebMethod (Description = " ID" )]
public GetReportResult GetReport( GetReportArg arg) {
// throw new SoapHeaderException(" ", SoapException.ClientFaultCode);
return new GetReportResult () {
Report = new FinReport {
ReportID = arg.ReportID,
Date = new DateTime (2015, 03, 15),
Info = getReportInfo(arg.ReportID)
}
};
}
private string getReportInfo( int reportID) {
StringBuilder sb = new StringBuilder ();
sb.Append( "ReportID = " ).Append(reportID).AppendLine();
if (HabraHeader != null ) {
sb.Append( "Login = " ).Append(HabraHeader.Login).AppendLine();
sb.Append( "Password = " ).Append(HabraHeader.Password).AppendLine();
}
foreach ( var header in UnknownHeaders) {
sb.Append( " SoapHeader = " ).Append(header.Element.Name).AppendLine();
sb.Append( "MustUnderstand = " ).Append(header.MustUnderstand).AppendLine();
// if (header.Element.Name == "HabraSoapHeader") {
// sb.AppendLine("HabraSoapHeader ");
// sb.Append("Login = ").Append(header.Element["Login"].InnerText).AppendLine();
// sb.Append("Password = ").Append(header.Element["Password"].InnerText).AppendLine();
// header.DidUnderstand = true;
// }
}
ResultTimeHeader = new ResultTimeSoapHeader ();
ResultTimeHeader.ResultTime = DateTime .Now;
return sb.ToString();
}
}
public class HabraSoapHeader : SoapHeader {
public string Login { get ; set ; }
public string Password { get ; set ; }
}
public class ResultTimeSoapHeader : SoapHeader {
public DateTime ResultTime { get ; set ; }
}
public class FinReport {
public int ReportID { get ; set ; }
public DateTime Date { get ; set ; }
public string Info { get ; set ; }
}
public class GetReportArg {
public int ReportID { get ; set ; }
}
public class GetReportResult {
public FinReport Report { get ; set ; }
}
}
private void webMethodTest_GetReport() {
var service = GetFinReportService();
var arg = new GetReportArg ();
arg.ReportID = 45;
service.HabraSoapHeaderValue = new HabraSoapHeader ();
service.HabraSoapHeaderValue.Login = "neo" ;
service.HabraSoapHeaderValue.Password = "3Ku2kcQfNLOW" ;
service.HabraSoapHeaderValue.MustUnderstand = true ;
var result = service.GetReport(arg);
var resultTimeSoapHeader = service.ResultTimeSoapHeaderValue;
if (resultTimeSoapHeader != null ) {
MessageBox .Show( "ResultTimeSoapHeader = " + resultTimeSoapHeader.ResultTime);
}
MessageBox .Show(result.Report.Info);
}
<? xml version = " 1.0 " encoding = " UTF-8 " ?>
< soap:Envelope xmlns:soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd = " http://www.w3.org/2001/XMLSchema " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Header >
< HabraSoapHeader xmlns = " http://asmx.habrahabr.ru/ " soap:mustUnderstand = " 1 " >
< Login > neo </ Login >
< Password > 3Ku2kcQfNLOW </ Password >
</ HabraSoapHeader >
</ soap:Header >
< soap: Body >
< GetReport xmlns = " http://asmx.habrahabr.ru/ " >
< arg >
< ReportID > 45 </ ReportID >
</ arg >
</ GetReport >
</ soap:Body >
</ soap:Envelope >
<? xml version = " 1.0 " encoding = " UTF-8 " ?>soap:mustUnderstand=«1», , - . SoapHeader public bool DidUnderstand { set; get; }, , . true, – false. , mustUnderstand=«1», DidUnderstand false, - soap:Fault. [SoapHeader(«HabraHeader»)], :
< soap:Envelope xmlns:soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd = " http://www.w3.org/2001/XMLSchema " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Header >
< ResultTimeSoapHeader xmlns = " http://asmx.habrahabr.ru/ " >
< ResultTime > 2015-03-24T11:37:00.6135717+06:00 </ ResultTime >
</ ResultTimeSoapHeader >
</ soap:Header >
< soap: Body >
< GetReportResponse xmlns = " http://asmx.habrahabr.ru/ " >
< GetReportResult >
< Report >
< ReportID > 45 </ ReportID >
< Date > 2015-03-15T00:00:00 </ Date >
< Info >
ReportID = 45
Login = neo
Password = 3Ku2kcQfNLOW
</ Info >
</ Report >
</ GetReportResult >
</ GetReportResponse >
</ soap:Body >
</ soap : Envelope >
<? xml version = " 1.0 " encoding = " UTF-8 " ?>public SoapUnknownHeader[] UnknownHeaders { get; set; }, foreach.
< soap:Envelope xmlns:soap = " http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd = " http://www.w3.org/2001/XMLSchema " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " >
< soap: Body >
< soap: Fault >
< faultcode > soap:MustUnderstand </ faultcode >
< faultstring > SOAP HabraSoapHeader . </ faultstring >
</ soap:Fault >
</ soap:Body >
</ soap:Envelope >
[ WebMethod (Description = " ID" , CacheDuration = 5)]soap . , - , .
public GetReportResult GetReport( GetReportArg arg){
return new GetReportResult (){
Report = new FinReport {
ReportID = arg.ReportID,
Date = DateTime .Now,
Info = getReportInfo(arg.ReportID)
}
};
}
private string getReportInfo( int reportID){
string key = "getReportInfo_" + reportID;
string cachedInfo = Context.Cache.Get(key) as string ;
if (cachedInfo != null ){
return cachedInfo;
}
string info = DateTime .Now + " reportID = " + reportID;
this .Context.Cache.Add(key, info, null , DateTime .Now.AddSeconds(10), TimeSpan .Zero, CacheItemPriority .High, null );
return info;
}
HTTP Error 500.19 — Internal Server Error.or
The requested page cannot be accessed because the related configuration data for the page is invalid.
Access is denied..
Error message 401.3: You do not have permission to view this directory or page using the credentials you supplied
«FinReportWebService» . , .
Could not load file or assembly 'FinReportWebService' or one of its dependencies. An attempt was made to load a program with an incorrect format.- Enable 32-Bit Applications .
%systemroot%\System32\inetsrv\appcmd list wp
%systemroot%\System32\inetsrv\appcmd list sites
%systemroot%\System32\inetsrv\appcmd list app
%systemroot%\System32\inetsrv\appcmd list appPools
pause
Source: https://habr.com/ru/post/254165/
All Articles