spring.net 整合Webservice小计

按照刘冬的


Spring.NET学习笔记21——整合Web Service(应用篇) Level 200 ,用VS2012实现

几处修改:

服务器端

1、在Global.asax的Application_Start中实例化Spring.NET容器

WebApplicationContext ctx = ContextRegistry.GetContext() as WebApplicationContext;

此事可以不做

2、Web.config配置

<?xml version="1.0"?>
<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
    </sectionGroup>
    
  </configSections>
 
  <spring>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/>
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data"/>
    </parsers>
    <context>
      <resource uri="assembly://Jesus.Repository/Jesus.Repository.Config/Repository.xml"/>
    </context>
  </spring>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime maxRequestLength="2147483647" executionTimeout="600"/>
    <httpHandlers>
      <add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers>
      <add name="SpringWebServiceSupport" verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
    </handlers>
  </system.webServer>
  <object id="UsersServer" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
    <property name="TargetName" value="wsUsers"/>
    <property name="Namespace" value="<a target=_blank href="http://Jesus.ZXJ/'/">http://Jesus.ZXJ/"/</a>>
  </object>
</configuration>

其中

    <httpHandlers>
      <add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
    </httpHandlers>

在VS2012中可以没有,但在VS2010中必须有

wsUsers对应的是PersonContract  类Spring节点配置

3、必要引用 ---Spring.Web


客户端

1、App.config配置

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
    </sectionGroup>
  </configSections>

  <spring>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/>
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data"/>
    </parsers>
    <context>
      <resource uri="assembly://Jesus.BLL/Jesus.BLL.Config/Webservice.xml"/>
    </context>
  </spring>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <appSettings>
    <add key="skin" value="Coffee"/>
    <add key="url" value="localhost:2727"/>
  </appSettings>
 
  
</configuration>



2、Webservice.xml配置

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
  <object id="wsUsers" type="Jesus.SysUtility.Factory.WebServiceProxyFactory,Jesus.SysUtility">
    <constructor-arg value="UsersServer"/>
    <property name="ServiceInterface" value="Jesus.WebserviceInterface.BasicInformation.IUsers, Jesus.WSI"/>
  </object>
</objects>

其中<property name="ServiceInterface" value="Jesus.WebserviceInterface.BasicInformation.IUsers, Jesus.WSI"/>对应的是interface IPersonContract
3、Jesus.SysUtility.Factory.WebServiceProxyFactory,Jesus.SysUtility实现代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jesus.SysUtility.Factory
{
    using Spring.Core.IO;
    using System.Net;
    public class WebServiceProxyFactory : Spring.Web.Services.WebServiceProxyFactory
    {
        static string _url;//= "10.73.58.102";

        static string URL{
            get{
                if (_url==null)
                {
                    _url = Jesus.Utility.AppConfigHelper.GetAppConfig("url");
                }
                return _url;
            }
        }
        public WebServiceProxyFactory(string webserviceName)
        {
            this.ServiceUri = new UrlResource(string.Format("http://{0}/{1}.asmx", URL, webserviceName));
            CredentialCache credentialCache = new CredentialCache();
            this.Credential = new System.Net.NetworkCredential("sfadministrator", "`qwe123");    
           
        }
    }
}
4、调用Webservice
public WebserviceInterface.BasicInformation.IUsers userManageSoapClient { get; set; }

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值