2012-09-20 13 views
6

Tôi đang viết một kịch bản PowerShell sẽ ping một dịch vụ web xà phòng cứ sau 10 phút để giữ cho nó nóng và sống để hiệu năng sẽ tăng lên. Chúng tôi đã thử nhiều kỹ thuật trong IIS với hồ bơi ứng dụng thời gian chờ nhàn rỗi và chỉ làm cho req http cho wsdl. Nhưng có vẻ như chúng tôi phải thực hiện yêu cầu thực sự đi xuống máy chủ sql khác một nhàn rỗi trong 90 phút sẽ làm cho nó để làm chậm cho các yêu cầu.Trong Powershell để tiêu thụ một SoapTypeType để giữ một dịch vụ xà phòng nóng

Tôi phải xây dựng một đối tượng tìm kiếm khá phức tạp để có thể thực hiện tìm kiếm thông minh sẽ giữ cho bộ nhớ cache được lưu trữ và nóng. Yêu cầu xà phòng nên trông như thế này:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fund="http://www.example.com/cmw/fff/fund" xmlns:tcm="http://www.example.com/cmw/fff/"> 
    <soapenv:Body> 
    <fund:Get> 
     <!--Optional:--> 
     <fund:inputDTO> 
      <fund:Fund> 
       <fund:Identity> 
       <fund:Isin>SE9900558666</fund:Isin> 
       <fund:FundBaseCurrencyId>SEK</fund:FundBaseCurrencyId> 
       </fund:Identity> 
      </fund:Fund> 
      <fund:InputContext> 
       <tcm:ExtChannelId>Channelman</tcm:ExtChannelId> 
       <tcm:ExtId>Rubberduck</tcm:ExtId> 
       <tcm:ExtPosReference>Rubberduck</tcm:ExtPosReference> 
       <tcm:ExtUser>Rubberduck</tcm:ExtUser> 
       <tcm:LanguageId>809</tcm:LanguageId> 
      </fund:InputContext> 
     </fund:inputDTO> 
    </fund:Get> 
    </soapenv:Body> 
</soapenv:Envelope>` 

Tôi cố gắng sử dụng New-WebServiceProxy hoạt động rất thanh lịch trong this example by powershellguy. Tôi xây dựng my own Objects as this example from technet.

Mã PowerShell tôi đã cố gắng cho đến nay là thế này:

$fundSrvc = New-WebServiceProxy -uri http://myColdServer:82/WSFund.svc?wsdl -NameSpace "tcm" 
# all the type are now defined since we called New-WebServiceProxy they are prefixed 
# with ns tcm 
[tcm.FundInput] $myFundGoofer = new-object tcm.FundInput 
[tcm.Fund] $myFund = new-object tcm.Fund 
[tcm.Context] $myInputContext = new-object tcm.Context 
[tcm.FundIdentity] $myFundIdentity = New-Object tcm.FundIdentity 
# Use these commands to get member of the objects you want to investigat 
# $myFundGoofer |Get-Member 
# $myFund |Get-Member 
# $myInputContext |Get-Member 
# $myFundIdentity |Get-Member 
$myFundIdentity.Isin="SE9900558666" 
$myFundIdentity.FundBaseCurrencyId="SEK" 
$myInputContext.ExtChannelId="ChannelMan" 
$myInputContext.ExtId="RubberDuck" 
$myInputContext.ExtPosReference="RubberDuck" 
$myInputContext.ExtUser="RubberDuck" 
$myInputContext.LanguageId="809" 
$myFund.Identity=$myFundIdentity 

$myFundGoofer.Fund = $myFund 
$myFundGoofer.InputContext = $myInputContext 

#Tada 
$fundSrvc.Get($myFundGoofer) 

Các Thông báo lỗi không có ý nghĩa đối với tôi. âm thanh của nó như: Cannot convert the "tcm.FundInput" value of type "tcm.FundInput" to type "tcm.FundInput"

Cannot convert argument "0", with value: "tcm.FundInput", for "Get" to type "tcm.FundInput": "Cannot convert the "tcm.FundInput" value of type "tcm.FundInput" to type "tcm.FundInput"." 
At C:\scripts\Service-TestTCM6.ps1:31 char:14 
+ $fundSrvc.Get <<<< ($myFundGoofer) 
    + CategoryInfo   : NotSpecified: (:) [], MethodException 
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument 
+3

Bạn đã thử cách này chưa? http://www.sqlmusings.com/2012/02/04/resolving-ssrs-and-powershell-new-webserviceproxy-namespace-issue/ –

+0

Không, nhưng bây giờ tôi sẽ gặp vấn đề này được mô tả trong liên kết của bạn nó có thể chạy một lần và sau đó tôi phải thay đổi không gian tên hoặc khởi động lại PowerShell. Nó hoạt động sau mỗi lần khởi động lại. Cảm ơn –

+0

Đừng đặt không gian tên trong dấu ngoặc kép. '$ fundSrvc = New-WebServiceProxy -uri http: // myColdServer: 82/WSFund.svc? wsdl -NameSpace tcm' –

Trả lời

6

Tôi làm theo các liên kết mà Christian (tín dụng nên đi với anh ta, nhưng tôi không biết làm thế nào để làm điều đó) đã và sử dụng không gian tên mặc định để thay thế. Vì vậy, bây giờ tôi không cần phải khởi động lại PowerShell mọi lúc. Có thể có một giải pháp khác để tiêu diệt đối tượng fundSrvc sau mỗi cuộc gọi. Nhưng tôi đã từ bỏ và đi với việc sử dụng không gian tên điên dài được tạo ra mặc định.

Dưới đây là giải pháp mà làm việc:

#note no -Namespace argument 
$fundSrvc = New-WebServiceProxy -uri "http://myColdServer/WSFund.svc?wsdl" 


#get autogenerated namespace 
$type = $fundSrvc.GetType().Namespace 
$myFundGooferDt = ($type + '.FundInput') 
$myFundDt = ($type + '.Fund') 
$myInputContextDt = ($type + '.Context') 
$myFundIdentityDt = ($type + '.FundIdentity') 
# Create the Objects needed 
$myFundGoofer = new-object ($myFundGooferDt) 
$myFund = new-object ($myFundDt) 
$myInputContext = new-object ($myInputContextDt) 
$myFundIdentity = New-Object $myFundIdentityDt 
# Assign values 
$myFundIdentity.Isin="SE9900558666" 
$myFundIdentity.FundBaseCurrencyId="SEK" 
$myInputContext.ExtChannelId="ChannelMan" 
$myInputContext.ExtId="RubberDuck" 
$myInputContext.ExtPosReference="RubberDuck" 
$myInputContext.ExtUser="RubberDuck" 
$myInputContext.LanguageId="809" 
$myFund.Identity=$myFundIdentity 

$myFundGoofer.Fund = $myFund 
$myFundGoofer.InputContext = $myInputContext 

#Tada 
$fundSrvc.Get($myFundGoofer) 
4

kỹ thuật ban đầu của bạn là đúng, bạn chỉ cần cũng bao gồm các thông số đẳng cấp trên New-WebServiceProxy. Để phần còn lại của mã của bạn.

Tôi gặp sự cố chính xác này khi làm việc với dịch vụ web từ PowerShell ngày hôm qua. Tôi cũng đã có nó làm việc bằng cách khám phá ra không gian tên được tạo tự động, nhưng điều đó cảm thấy một chút quá hacky cho ý thích của tôi.

Sau đó, tôi đã tìm thấy giải pháp được đề cập ở đây: https://groups.google.com/d/msg/microsoft.public.windows.powershell/JWB5yueLtrg/k0zeUUxAkTMJ

+1

bạn có thể thêm một ví dụ ngắn không? –