最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何解決Webservice第一次訪問特別慢的問題

 更新時(shí)間:2022年06月30日 09:57:24   作者:太陽(yáng)99  
這篇文章主要介紹了如何解決Webservice第一次訪問特別慢的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Webservice第一次訪問特別慢問題

最近做一個(gè)項(xiàng)目遇到首次加載webservice的時(shí)候特別慢,于是Google一番,得到結(jié)果是

<system.net>
    <defaultProxy enabled="false" useDefaultCredentials="false">
      <proxy/>
      <bypasslist/>
      <module/>
    </defaultProxy>
  </system.net>

原理是:由于web代理默認(rèn)是開啟的,也就是HttpWebRequest.DefaultWebProxy的值不為null,而這個(gè)DefaultWebProxy是一個(gè)全局變量。故第一次調(diào)用webservice方法的時(shí)候只有等這個(gè)默認(rèn)代理超時(shí)以后才能繞過(guò),所以第一次比較慢。

然而這個(gè)方法還不是特別慢的最大原因,所以即使這么做了效果依然沒有明顯的變快,于是又是一番的Google。

最終發(fā)現(xiàn)一個(gè)另一個(gè)因素:

原因很簡(jiǎn)單,就是因?yàn)樵诘谝淮芜B接Webservice時(shí),應(yīng)用程序動(dòng)態(tài)編譯生成序列化程序集導(dǎo)致的慢。

問題知道了那么就說(shuō)說(shuō)如何解決

1、首先如何提前生成序列化程序集

這個(gè)時(shí)候你會(huì)發(fā)現(xiàn)你的bin目錄下回生成一個(gè)“***.XmlSerializers.dll” 

2、接下來(lái)就簡(jiǎn)單了,在程序啟動(dòng)的時(shí)候就把這個(gè)文件加載進(jìn)來(lái)就OK了

Assembly.LoadFrom(Application.StartupPath + "\\***.XmlSerializers.dll");

        /// <summary>
        /// 應(yīng)用程序的主入口點(diǎn)。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool ok;
            var m = new System.Threading.Mutex(true, "***.exe", out ok);
            if (!ok) return;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Assembly.LoadFrom(Application.StartupPath + "\\***.XmlSerializers.dll");
            Application.Run(new FormMain());
            GC.KeepAlive(m);
        }

3、騷年啟動(dòng)你的應(yīng)用程序吧

cxf動(dòng)態(tài)調(diào)用Webservice接口

package cxfClient;
 
import org.apache.cxf.endpoint.Endpoint;
import javax.xml.namespace.QName;  
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
 
public class CxfClient { 
	public static void main(String[] args) throws Exception {
		String url = "http://localhost:9091/Service/SayHello?wsdl";
		String method = "say";
		Object[] parameters = new Object[]{"我是參數(shù)"};
		System.out.println(invokeRemoteMethod(url, method, parameters)[0]);
    }
	
	public static Object[] invokeRemoteMethod(String url, String operation, Object[] parameters){
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        if (!url.endsWith("wsdl")) {
            url += "?wsdl";
        }
        org.apache.cxf.endpoint.Client client = dcf.createClient(url);
        //處理webService接口和實(shí)現(xiàn)類namespace不同的情況,CXF動(dòng)態(tài)客戶端在處理此問題時(shí),會(huì)報(bào)No operation was found with the name的異常
        Endpoint endpoint = client.getEndpoint();
        QName opName = new QName(endpoint.getService().getName().getNamespaceURI(),operation);
        BindingInfo bindingInfo= endpoint.getEndpointInfo().getBinding();
        if(bindingInfo.getOperation(opName) == null){
        	for(BindingOperationInfo operationInfo : bindingInfo.getOperations()){
        		if(operation.equals(operationInfo.getName().getLocalPart())){
        			opName = operationInfo.getName();
        			break;
        		}
        	}
        }
		Object[] res = null;
		try {
			res = client.invoke(opName, parameters);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
    } 	
}

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

安吉县| 柘城县| 榆树市| 舞阳县| 巴林左旗| 枣强县| 常德市| 武清区| 深泽县| 湖口县| 石家庄市| 贵州省| 乌兰察布市| 新田县| 广平县| 平邑县| 济南市| 芒康县| 神池县| 视频| 威宁| 尉犁县| 斗六市| 马鞍山市| 克拉玛依市| 永靖县| 读书| 临夏县| 达日县| 涟源市| 北票市| 山丹县| 紫阳县| 边坝县| 和龙市| 栾川县| 靖州| 天津市| 建水县| 广西| 永州市|