2013-02-07 45 views
2

我寫下面的代碼來創建一個MM組件通過核心服務的tridion,但我得到的錯誤運行此服務,錯誤:找不到默認的終結點元素引用合同

public ComponentData GetNewMultimediaComponent(CoreServiceClient Client, string folderUri, string schemaUri, string title, FileInfo fi) 
    { 
     if (fi.Extension == ".png") 
     { 
      string mmType = GetMultiMediaType(fi.Extension); 
      if (mmType != null) 
      { 
       string tempLocation = ""; 

       UploadResponse us = new UploadResponse(); 
       using (StreamUploadClient streamClient = GetConnection()) 
       { 
        FileStream objfilestream = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read); 
        tempLocation = streamClient.UploadBinaryContent(fi.Name.ToLower(), objfilestream); 
       } 

       BinaryContentData bcd = new BinaryContentData 
       { 
        UploadFromFile = fi.FullName, 
        MultimediaType = new LinkToMultimediaTypeData { IdRef = mmType }, 
        Filename = fi.Name, 
        IsExternal = false 
       }; 

       ComponentData res = GetNewComponent(folderUri, schemaUri, title); 
       res.ComponentType = ComponentType.Multimedia; 
       res.BinaryContent = bcd; 

       res = (ComponentData)Client.Create(res, new ReadOptions()); 

在上面的代碼我收到錯誤下面一行

using (StreamUploadClient streamClient = new StreamUploadClient()) 



{System.InvalidOperationException: Could not find default endpoint element that references contract 'Tridion.ContentManager.CoreService.Client.IStreamUpload' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. 
     at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) 
     at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration) 
     at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) 
     at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) 
     at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) 
     at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory() 
     at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)....... 

只是爲了更新,我使用的tridion核心服務的DLL沒有配置文件,併成功創建連接。

連接設置

public StreamUploadClient GetConnection() 
    { 
     BasicHttpBinding basicHttpBinding = new BasicHttpBinding 
     { 
      MaxReceivedMessageSize = 10485760, 
      ReaderQuotas = new XmlDictionaryReaderQuotas 
      { 
       MaxStringContentLength = 10485760, 
       MaxArrayLength = 10485760 
      }, 
      Security = new BasicHttpSecurity 
      { 
       Mode = BasicHttpSecurityMode.None, 
      } 
     }; 

     EndpointAddress remoteAddress = new EndpointAddress("http://abc/webservices/CoreService2011.svc/streamUpload_basicHttp"); 

     StreamUploadClient client = new StreamUploadClient(basicHttpBinding, remoteAddress); 
     try 
     { 
      client.Open(); 
     } 
     catch (Exception ex) 
     { 
      //log.Error("Error:CoreServiceConectionOpen:Common:" + ex.Message); 
      throw ex; 
     } 

     return client; 
    } 

現在,越來越下面一行

tempLocation = streamClient.UploadBinaryContent(fi.Name.ToLower(), objfilestream); 

{System.ServiceModel.ProtocolException: The content type multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1";start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 560 bytes of the response were: ' 
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1 
Content-ID: <http://tempuri.org/0> 
Content-Transfer-Encoding: 8bit 
Content-Type: application/xop+xml;charset=utf-8;type="text/xml" 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:FilePath xmlns:h="http://www.sdltridion.com/ContentManager/CoreService/2011">C:\Windows\TEMP\tmp6841.png</h:FilePath></s:Header><s:Body><UploadResponse xmlns="http://www.sdltridion.com/ContentManager/CoreService/2011"/></s:Body></s:Envelope> 
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1-- 
'. 

錯誤的任何一個可以幫助我解決這個問題?

回答

4

的問題是在這條線:

StreamUploadClient streamClient = new StreamUploadClient() 

這是你試圖連接到一個單獨的終結點。通常,它會從app.config中選擇地址和所有其他連接屬性,但由於您沒有任何需要自己提供所有必需的參數,所以與您使用CoreService進行的操作類似。請參閱app.config示例以查看需要哪些參數。

事情是這樣的:

public StreamUploadClient GetConnection() 
    { 
     BasicHttpBinding basicHttpBinding = new BasicHttpBinding 
     { 
      MaxReceivedMessageSize = 10485760, 
      ReaderQuotas = new XmlDictionaryReaderQuotas 
      { 
       MaxStringContentLength = 10485760, 
       MaxArrayLength = 10485760 
      }, 
      MessageEncoding = WSMessageEncoding.Mtom, 
      Security = new BasicHttpSecurity 
      { 
       Mode = BasicHttpSecurityMode.None, 
      } 
     }; 

     EndpointAddress remoteAddress = new EndpointAddress("http://abc/webservices/CoreService2011.svc/streamUpload_basicHttp"); 

     StreamUploadClient client = new StreamUploadClient (basicHttpBinding, remoteAddress); 
     try 
     { 
      client.Open(); 
     } 
     catch (Exception ex) 
     { 
      log.Error("Error:CoreServiceConectionOpen:Common:" + ex.Message); 
      throw ex; 
     } 

     return client; 
    } 
+0

我不使用app.config文件,現在在這種情況下,我需要做什麼?正如你所能找到的,我傳遞了具有所有連接細節的客戶端對象。 –

+0

我已經添加了我的連接代碼問題 –

+0

我理解你的觀點,但是當我像這種方式去獲取以上錯誤 tempLocation = streamClient.UploadBinaryContent(fi.Name.ToLower(),objfilestream); 錯誤:我理解你的觀點,但是當我像這樣去上面的錯誤{System.ServiceModel.ProtocolException:內容類型multipart/related;類型= 「應​​用/ XOP + xml」 的;開始= 「」;邊界= 「UUID:739a821f-aee2-4eaf-9206-05a1ed19311c + ID = 1」;啓動信息=響應消息的「text/xml」與綁定的內容類型不匹配(text/xml ... –

相關問題