ASP.NET 访问Web Service 失败
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ASP.NET 访问Web Service 失败相关的知识,希望对你有一定的参考价值。
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。
分析器错误信息: 未能创建类型“ServicesAccessDataBase”。
源错误:
行 1: <%@ WebService Language="C#" CodeBehind="~/App_Code/ServicesAccessDataBase.cs" Class="ServicesAccessDataBase" %>
源文件: /test/ServicesAccessDataBase.asmx 行: 1
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; ASP.NET 版本:2.0.50727.1433
调了一天了还是没搞定,那位大哥帮帮忙呀!
本地调试没有问题放在虚拟空间上存在问题。
ASP.NET Web Service 标准SOAP开发案例代码(自定义验证安全头SOAPHeader)
using System.Xml;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
using System.Configuration;
using Service.Common.Constant;
namespace Service.Common.Core.Head.Safe
{
/// <summary>
/// 为了安全,自定义的Soap头
/// </summary>
[XmlRoot("Security", Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public class Security : SoapHeader
{
Token _userNameTokern = new Token();
public Token UsernameToken
{
get { return _userNameTokern; }
set { _userNameTokern = value; }
}
/// <summary>
/// 传入要正确的用户名和密码,与消息头中存储的用户名和密码,进行对比。
/// </summary>
/// <param name="rightUserName"></param>
/// <param name="rightPassWord"></param>
/// <returns></returns>
public bool IsAuthorized(string rightUserName, string rightPassWord)
{
return this.UsernameToken.Username == rightUserName &&
this.UsernameToken.Password.Value == rightPassWord;
}
/// <summary>
/// 公共的构造SOAP Header方法
/// </summary>
/// <returns></returns>
public static Security ConstructSafeHead(string username, string passwordvalue, string passwordtype)
{
Security soapheader = new Security();
soapheader.UsernameToken = new Token();
soapheader.UsernameToken.Username = username;
soapheader.UsernameToken.Password = new Password();
soapheader.UsernameToken.Password.Value = passwordvalue;
soapheader.UsernameToken.Password.Type = passwordtype;
return soapheader;
}
}
}
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using Service.ESB.BaseData.Operation;
using Service.Common.Core.ESB.Request;
using Service.Common.Core.Head.Safe;
using Service.Common.Core.ESB.Response;
using Service.Common.Core.Base;
using Service.ESB.BaseData.Simulation;
using Service.Common.Log;
using Service.Common.Core.Head.Test;
using System.Xml;
using System.Xml.Serialization;
using Service.Common;
using Service.Common.Core.ESB.Base;
using Service.Common.Constant;
using Service.ESB.BaseData.Simulation.Operation;
namespace Service.ESB.BaseData
{
/// <summary>
/// 模拟ESB总线数据通用服务的类
/// </summary>
[WebService(Namespace = "http://www.iec.ch/TC57/2008/schema/message")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[XmlRoot(Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class SimulativeDataCommonService
{
#region 私有字段
/// <summary>
/// 安全头
/// </summary>
private Security _safeSoapHeader;
/// <summary>
/// 测试标识头
/// </summary>
private TestCaseHead _testCaseHeader;
#endregion
#region 公开的属性
[XmlElement(Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Security SafeSoapHeader
{
get { return _safeSoapHeader; }
set { _safeSoapHeader = value; }
}
public TestCaseHead TestCaseHeader
{
get { return _testCaseHeader; }
set { _testCaseHeader = value; }
}
#endregion
#region 服务方法
[SoapHeader("SafeSoapHeader")]//安全头
[SoapHeader("TestCaseHeader")]//测试标识头--用于测试时标示
[SoapDocumentMethod(RequestElementName = "RequestMessage", ResponseElementName = "ResponseMessage")]
[WebMethod(Description = "模拟数据通用服务的接口")]
[return: XmlElement("RequestMessage"), XmlElement("Header", typeof(HeaderClass)), XmlElement("Reply", typeof(ReplyClass))]
[XmlInclude(typeof(RequestMessage)), XmlInclude(typeof(ResponseMessage))]
public object[] invokeDataService(HeaderClass reqMsgHeader, RequestClass reqMsgRequest)
{
}
}
以上是关于ASP.NET 访问Web Service 失败的主要内容,如果未能解决你的问题,请参考以下文章
通过 ServiceProxy 访问无状态服务失败 + ASP.NET 5 Web API 项目引发健康状态错误
ASP.NET Web API 2 - 用户注册电子邮件确认失败
使用 JQuery 访问 ASP.net Web 服务时出错 - JSONP
asp.net ajax客户端框架如何调用Web Service